Question

How do I revert the altered values of ALL the dirty entities in the data store to their original store values?

The entities that need to be updated are a parameter for the procedure ObjectContext.Refresh.

1
14
11/17/2009 6:18:55 AM

Accepted Answer

Typically, the following works:

Context.Refresh(RefreshMode.StoreWins, _
    Context.ObjectStateManager.GetObjectStateEntries())

It sometimes interferes with EntityRelations. See my remark for further information.

16
1/13/2010 3:35:55 PM

Popular Answer

This code is usable:

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.Deleted 
                                               | EntityState.Modified 
                                               | EntityState.Unchanged)
                                      where entry.EntityKey != null
                                      select entry.Entity);

     context.Refresh(RefreshMode.StoreWins, refreshableObjects);
}

I detailed how to RefreshAll() and refresh the context in another article, as follows:

http://christianarg.wordpress.com/2013/06/13/entityframework-refreshall-loaded-entities-from-database/



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow