如何将对象的跟踪信息从 ObjectContext 更改为另一个?
我有一个被添加到 objectContext 的对象。
在某些操作之后,我需要将其传递到同一数据库的另一个 objectcontext,但我总是遇到此消息:
实体对象不能被 IEntityChangeTracker 的多个实例引用。
我需要更改跟踪信息,将其与旧对象分离并将其附加到新对象上下文。
但在新范围中,我不拥有旧对象上下文,无法在
我的问题之前将其分离:如何更改此对象的跟踪信息到新的ObjectContext?
I have an object which is added to an objectContext ..
after some operation i need to pass it to another objectcontext of the same database but i always face this message :
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
i need to change tracking information be detach it from the old object and attach it to the new objectcontext..
but in the new scope i doesn't own the old objectContext to detach it before
My question : How to change Tracking information of this object to the new ObjectContext?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当第一个上下文仍在范围内时,您必须将实体从该上下文中
分离
。由于上下文是工作单元,因此您需要执行此操作并且遇到上下文范围问题,这一事实表明您可能需要更广泛地审视您的设计。You must
Detach
the entity from the first context while that context is still in scope. Since contexts are units of work, the fact that you need to do this at all and are having context scoping issues suggests you might want to take a broader look at your design.