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

How to extract domain from URLHow to extract domain from URL

You want to extract a domain from URL. The list of URLs to support might be as below. For this list you expect the domain sub.domain.com : sub.domain.com/folder?p1=v1 www.sub.domain.com/folder?p1=v1 http://sub.domain.com/folder?p1=v1 https://sub.domain.com/folder?p1=v1 https://www.sub.domain.com/folder?p1=v1

%d bloggers like this: