C#:实现框架EF增删查改

新增

public ActionResult Index()
        {
             var classinfo = new ClassInfo()
            {
                Name = "2018173807",
                Remark = "七班",
                Term = 2,
               TeacherID = 1
            };
            db.ClassInfos.Add(classinfo);
            db.SaveChanges();
            return View();
        }

修改

public ActionResult Index()
        {
var szx = db.ClassInfos.Find(4);
            szx.Remark = "六班";
             db.SaveChanges();
            return View();
            }

删除

public ActionResult Index()
        {
var a = db.ClassInfos.Find(4);
            db.ClassInfos.Remove(a);
             db.SaveChanges();
            return View();
            }

你可能感兴趣的:(C#:实现框架EF增删查改)