Linq 常用操作(增删改)
增加 using(var db = new Entities()) { //数据操作 UserInfo user = new UserInfo() { UserName = "zhangsan1", UserPass = "123123" }; db.UserInfo.Add(user); db.SaveChanges(); } 删除 先查询-再删除 using (var db = new Entities()) { var user = (from v in db.UserInfo where v.UserID == 14 select v).Single(); db.UserInfo.Remove(user); db.SaveChanges(); } 修改单个实体 先查询-再修改 using (var db = new Entities()) { var user = (from v in db.UserInfo where v.UserName == "zhangsan" select v).Single(); user.UserPass = "123456"; db.SaveChanges(); }