EntityFramework DbContext RefreshAll loaded entities from Database

In my previous post I’ve explained how to refresh all Entities using the ObjectContext API. https://christianarg.wordpress.com/2013/06/13/entityframework-refreshall-loaded-entities-from-database/

Using the newer, nicer, and recommended DbContextApi (actually ObjectContext API will be removed in EF7) the code becomes much simpler:

public void RefreshAll()
{
     foreach (var entity in ctx.ChangeTracker.Entries())
     {
           entity.Reload();
     }
}

I must admin I haven’t tested this as much as the ObjectContext version.

Advertisements

One thought on “EntityFramework DbContext RefreshAll loaded entities from Database

  1. Pingback: EntityFramework RefreshAll loaded entities from Database | Software must be beautiful

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s