Ahm*_*mel 3 c# asp.net-mvc entity-framework
我想更新实体框架中的多个列。我现在用这个:
var user = new Relations { Id=1, Status = 1, Date = DateTime.Now, Notification = 0 };
db.Relations.Attach(user);
db.Entry(user).Property(x => x.Status).IsModified = true;
db.Entry(user).Property(x => x.Notification).IsModified = true;
db.Entry(user).Property(x => x.Date).IsModified = true;
db.Configuration.ValidateOnSaveEnabled = false;
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
db.Entry(user).Property
有没有更好的方法来更新列而不需要多次重复代码?
EntityState
你可以像这样使用:
var user=db.users.Find(userId);
user.name="new name";
user.age=txtAge.text;
user.address=txtAddress.text;
context.Entry(user).State=Entitystate.Modified;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11718 次 |
最近记录: |