什么是ObjectContext.ApplyCurrentValues对的DbContext相当于 [英] What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext
问题描述
什么是ObjectContext.ApplyCurrentValues对的DbContext等价?
What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext?
推荐答案
有没有等价的。您可以用得到的ObjectContext ...
There is no equivalent. You can either get the ObjectContext with...
((IObjectContextAdapter)myDbContext).ObjectContext.ApplyCurrentValues(...)
...或者使用类似的方法 DbEntityEntry
:
...or use a similar method of DbEntityEntry
:
myDbContext.Entry(originalEntity).CurrentValues.SetValues(changedEntity);
originalEntity
表示更改前的对象(通常是从数据库中读取更新之前)。它必须被附加到上下文。 changedEntity
表示与已经改变了相同密钥的实体。
originalEntity
represents the object before the change (usually fetched from database before you update). It must be attached to the context. changedEntity
represents the entity with the same key which has been changed.
这第二种方法可能是密切相关的 ObjectStateEntry.ApplyCurrentValues
EF 4.0
的方法。
This second approach is probably closely related to the ObjectStateEntry.ApplyCurrentValues
method of EF 4.0
.
这篇关于什么是ObjectContext.ApplyCurrentValues对的DbContext相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!