Q:

Undo changes made to a entity row

Undo changes to a Row that's bound to text box's in a form.
I use the entity framework to save and update the data so I have no control on what gets saved. If the user hits Cancel on the form I want all the changes to the row to get reverted back to what they where before.
The same problem I have with new row's I have the new row created on starting the form, how can I get rid of it before it gets saved to the database?
Thanks a lot. 

A:

The correct way is to dispose context with modified data, create new context and reload data from database. EF doesn't have any direct way to cancel changes. If you don't want to do it you must manually iterate entities in ObjectStateManager (ChangeTracker in DbContext API) and based on their state either detach them (for added rows) or rewrite actual values with original values. If you also modified relations the task will become really complex and in such case it is really good idea to follow my former advice.

