How to clear contents of ObjectContext in Entity Framework 1.0

瘦欲@ 提交于 2019-12-12 05:39:09

问题


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


回答1:


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();
}



回答2:


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



来源:https://stackoverflow.com/questions/3774395/how-to-clear-contents-of-objectcontext-in-entity-framework-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!