开发者

How to clear contents of ObjectContext in Entity Framework 1.0

开发者 https://www.devze.com 2023-01-17 18:07 出处:网络
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.

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号