如何将对象的跟踪信息从 ObjectContext 更改为另一个?

发布于 2024-08-31 17:10:18 字数 270 浏览 10 评论 0原文

我有一个被添加到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年九夏 2024-09-07 17:10:18

当第一个上下文仍在范围内时,您必须将实体从该上下文中分离。由于上下文是工作单元,因此您需要执行此操作并且遇到上下文范围问题,这一事实表明您可能需要更广泛地审视您的设计。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文