Monthly Archives: July 2015

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.