标签:style blog http io color os ar for sp
1.常用
db.Entry(实体).State = EntityState.Modified;
db.SaveChanges();
2.指定更新
db.Configuration.ValidateOnSaveEnabled = false;
db.TUser.Attach(实体);
ObjectStateEntry stateEntry = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(实体);
stateEntry.SetModifiedProperty("字段1");
stateEntry.SetModifiedProperty("字段2");
db.SaveChanges();
db.Configuration.ValidateOnSaveEnabled = true;
3.指定更新(推荐!好用!)
TConsultant model = db.TConsultant.FirstOrDefault(t => t.ID == iID);
if (TryUpdateModel(model, new string[] { "Name", "Sex", "PhoneNuber", "CertificateNumber", "Email", "QQ", "Culture" }))
{
db.SaveChanges();
return Content("修改成功!");
}
4.
标签:style blog http io color os ar for sp
原文地址:http://www.cnblogs.com/lee2011/p/4060108.html