views:

642

answers:

2

How to update ALL the dirty entities from the data store, and reset their changed values to the original store value?

The method ObjectContext.Refresh requires as a parameter the entities to be refreshed.

A: 

If you want to reset ALL the changes, you could set the ObjectContext to null and re-instantiate it.

I believe this will achieve what you want.

Kindness,

Dan

Daniel Elliott
I guess you work with ASP.NET, so it's easy for you to say it, I use a long life-cycle context instance.
Shimmy
+4  A: 

The following usually works:

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

It sometimes causes problems with EntityRelations. look at my comment for further details.

Shimmy
This just saved me many lines of code walking the object graph myself.
Daniel Brückner
There is a bug, please take a look: http://stackoverflow.com/questions/1757872/undelete-an-entity-marked-as-entitystate-delete
Shimmy
Sometimes you'd like to update even the unchanged items, cuz you want to refresh them against the changes made in database by other clients.
Shimmy