Undo changes to context when using EntityFramework 4.0/4.1
-
-
I have Invoice entity wich I change and then add InvoiceRows and then I want to cancel the whole operation. What is the easiest way of doing this? I can use Context.refresh() to get a fresh copy of my Entity but is this really the way to do it? //h
I would use
Context.Refresh(RefreshMode.StoreWins, obj)
as my "Plan B". My "Plan A" would be keeping changes outside ofContext
until they are ready to be committed, and then apply and commit them in an atomic operation. This requires more work as you need to track the state of newly added entities, but I think it is worth it, because the approach is cleaner overall. -
I have Invoice entity wich I change and then add InvoiceRows and then I want to cancel the whole operation. What is the easiest way of doing this? I can use Context.refresh() to get a fresh copy of my Entity but is this really the way to do it? //h
Transaction. I've not worked with them with Entity Framework myself, but that seems like what you want.
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.