I have not found a specific post here on how to rollback previous operation on sql server if one operation in a set of operations fails.
I have for instance one query to bring some data them I add a row with context.saveChanges(), then perhapes a second and a third insert are performed.
Ok, this last insert fails, so I want to get the db state to the state it was before the three inserts.
I am using EF4, and SQL Server 2008 R2 + Asp Net MVC 4 / C#.
Is transaction the only way to do it?
As thoses operations has been saved one by one (programatically) and not in just one context.saveChange(), I am not sure how to perform the rollback.
You can do “nested transactions” like this using TransactionScope.
Wrap your logic in