Reputation: 31
I'm currently testing the entity framework 4 for a simple app I wish to build.
I've searched high and low for the answer to this without any luck!!
My question is how do you save and cancel changes on a record basis? Using the save changes method on the context persists all the changes to the database. Is there a way to control this?
Thanks Gary
Upvotes: 3
Views: 2604
Reputation: 3512
Sounds like you want to work in a disconnected fashion.
You might also want to look into different EF templates such as self tracking entities which may make your life a bit easier as they generate entities which can track changes themselves outside of a data context; however this might be overkill for a simple app.
Upvotes: 0
Reputation: 2387
You shouldn't use a singular Data Context for all the operations in the lifetime of your application. Spin up a session (create a Data Context) for each atomic operation you want to make. Call SaveChanges to submit the operation, simply dispose of the context without saving changes to 'cancel' the operation.
Upvotes: 7