无法使ApplyCurrentValues(Entity)在Entity Framework 5中工作

同志们,任何人都可以帮助我,entity framework5似乎没有ApplyCurrentValues()方法。 是否有另一种方法来更新entity frameworkv5中的数据库对象。 这是我想要做的

odc.Accounts.Attach(new Account { AccountID = account.AccountID }); odc.Accounts.ApplyCurrentValues(account); odc.SaveChanges(); 

但是我在ApplyCurrentValues()行中遇到了编译错误

ApplyCurrentValues是一个ObjectContext API方法,因此首先您必须访问包含在DbContext中的DbContext

 odc.Accounts.Attach(new Account { AccountID = account.AccountID }); ((IObjectContextAdapter)odc).ObjectContext .ApplyCurrentValues("Accounts", account); odc.SaveChanges(); 

请注意,包装的上下文没有像“Accounts”这样的成员,因此您必须使用ObjectContext方法本身。

但您可以使用DbContext API执行相同的操作:

 var sourceAcc = new Account { AccountID = account.AccountID }); odc.Entry(account).CurrentValues.SetValues(sourceAcc);