We need an easy way to give the user the "Cancel" functionallity when he make changes to entities data but he does not want to save changes pressing Cancel button. I think adding DiscardChanges to ObjectContext is the solution, going back to its initial state and dissapearing added entities (even child entities) and returning modified or deleted entities to their original state
This looks like the optimal solution when using a singleton or long running DbContext.
However when working with short-lived contexts for example in ASP.NET apps, transactions is another good way to achieve this.
Julien N commented
@Max, last time I tried, Refresh only does a partial job : it only refresh properties and not relationships.
Moreover, added or deleted items are not removed or restored.
Discarding the context is the "standard" solution, but it causes a lot of other issues, especially existing entities are now "contextless" and must be attached to the new context.
On many projects I'd love to see this feature exist !
Jose, These line of code would partially do the job
public void DiscardChanges()
private ObjectSet<T> GetObjectSet()