Reputation: 411
I'm wondering if it is possible to refresh all entities from data model as opposite to refresh them one by one.
Something like entities.RefreshAll();
Upvotes: 1
Views: 2725
Reputation: 964
Yes you can use this code:
public void RefreshAll()
{
// Get all objects in statemanager with entityKey
// (context.Refresh will throw an exception otherwise)
var refreshableObjects = (from entry in context.ObjectStateManager.GetObjectStateEntries(
EntityState.Added
| EntityState.Deleted
| EntityState.Modified
| EntityState.Unchanged)
where entry.EntityKey != null
select entry.Entity);
context.Refresh(RefreshMode.StoreWins, refreshableObjects);
}
I wrote another couple of ways of refreshing with EF:
Upvotes: 2