如何清除Entity Framework 1.0中ObjectContext的内容

发布于 2024-09-24 09:46:36 字数 99 浏览 9 评论 0原文

是否有手动清除/重置 ObjectContext 回到其初始状态的方法?请注意,我不能只是实例化一个新上下文。

这是使用 1.0 版本的实体框架。

谢谢

Is there a method of manually clearing/resetting an ObjectContext back to its initial state? Note that I can't just instantiate a new context.

This is using the 1.0 version of the Entity Framework.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

扭转时空 2024-10-01 09:46:36

ObjectContext 是一个短暂的对象,不应该像这样被缓存。正常使用应该是这样的:

using(var ctx = new MyContext())
{
    // Select/update/insert/delete
    ctx.SaveChanges();
}

ObjectContext is meant to be a short-lived object, it shouldn't be cached like that. Normal usage should look like:

using(var ctx = new MyContext())
{
    // Select/update/insert/delete
    ctx.SaveChanges();
}
深居我梦 2024-10-01 09:46:36

您可以尝试调用 Detach 方法对于加载到上下文的每个实体。

You can try to call the Detach method for each entity that was loaded to the context.

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