什么是ObjectContext.ApplyCurrentValues​​对的DbContext相当于 [英] What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext

查看:245
本文介绍了什么是ObjectContext.ApplyCurrentValues​​对的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆