1、新增
首先建一个User控制器,然后对齐进行新增代码的编写,如下:
public ActionResult Add(){UserInfo userInfo = new UserInfo(){Account = \"long\",Pwd = \"123\"};db.UserInfos.Add(userInfo);db.SaveChanges();return View();}
2、删除
根据ID进行删除
public ActionResult Delete(){var user = db.UserInfos.Find(i);db.Entry(user).State = System.Data.Entity.EntityState.Deleted;db.SaveChanges();return View();}
3、修改
把ID为1的Account信息修改为“long”
public ActionResult Edit(){UserInfo userInfo = new UserInfo(){ID = 1,Account = \"long\"};db.Entry(userInfo).State = System.Data.Entity.EntityState.Modified;db.SaveChanges();return View();}