How To: Refresh POCO entity from DbContext

If you notice that the context returns the same entity even if it is already changed one line before, you probably what the following

ObjectContext context = ((IObjectContextAdapter)this.Context).ObjectContext;
context.Refresh(RefreshMode.StoreWins, entity);

You can use it right after obtaining an entity with a statement like follows:

var order = this.Context.Order.Single(e => e.ID == id);

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Post

%d bloggers like this: