code first EF mvc 使用

来源:互联网 发布:易玩网络 编辑:程序博客网 时间:2024/05/17 04:23

http://www.cnblogs.com/libingql/p/3330880.html



http://www.cnblogs.com/powertoolsteam/p/aspnet-mvc5-controller.html



http://www.cnblogs.com/yukaizhao/archive/2010/05/13/linq_to_sql_1.html



 [HttpPost]
        public JArray GetShuXingInfoArr(ShuXingBingding model)
        {
            JArray ja = new JArray();
            string sql = "SELECT * FROM ShuXings;";


            //ShuXingView data1 = db.Database.SqlQuery<ShuXingView>(sql);
            //ja = db.Database.SqlQuery<JArray>(sql);


            var arrrr = db.Database.SqlQuery<ShuXingView>(sql).ToList();
            var www = from u in db.ShuXings select u;
            var arr=db.ShuXings.ToList();
            ShuXingView modelH = new ShuXingView();
            if (arr.Count() > 0) {
                for (int i = 0; i < arr.Count(); i++)
                {
                    JObject jo = new JObject();
                    jo.Add("ShuXingId", arr[i].ShuXingId);
                    jo.Add("ShuXingName", arr[i].ShuXingName);
                    ja.Add(jo);
                }
            }


            ShuXing shuXing = db.ShuXings.Find(model.Id);
           
            JObject jo1 = new JObject();
            jo1.Add("Id", shuXing.Id);
            //query.
            //ja = query.ToArray<JArray>();
            return ja;
        }
        public ActionResult DeteleZ(int id)
        {
            JsonResult jrResult = new JsonResult();
            try
            {
                string sql = "UPDATE ShuXings SET ShuXingId='222' WHERE Id='1'";
                db.Database.ExecuteSqlCommand(sql);


                sql = "DELETE from ShuXings where Id='2';";
                db.Database.ExecuteSqlCommand(sql);
            }
            catch (Exception)
            {


                throw;
            }
           
            return jrResult;
        }

0 0
原创粉丝点击