Csharp/C#教程:无法使ApplyCurrentValues(Entity)在Entity Framework 5中工作分享


无法使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执行相同的操作:

上述就是C#学习教程:无法使ApplyCurrentValues(Entity)在Entity Framework 5中工作分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1013066.html

(0)
上一篇 2021年12月30日
下一篇 2021年12月30日

精彩推荐