Reputation: 36
I have a WPF app that uses EF4.3.1 to conenct to DB. I'm displaying an entity in a form in which user can edit the values and hit save or cancel. The problem is that when the user hits cancel the changes don't get rolled back the entity is still getting tracked by the context and gets saved to the database when the saveChanges() is called by some other operation. I was wondering if you can point me to a good source on implementing EF/WPf client server application.
The other side effect is that if the user has two forms open and hits save on one.. the other one gets saved as well.. clearly I'm not using it correctly.
Upvotes: 1
Views: 500
Reputation: 506
What I've been doing in this scenario is that I make a copy of the entity and give the copy to the user to edit. When the user hits cancel I simply trash the copy. On save I overwrite the original entity's properties with values from the copy (now modified by the user), save the original and trash the copy.
Upvotes: 3