I need help implementing a rather complex business logic that runs on many tables and executes a lot of SQL commands. However, I want to be sure that the data will not remain in an unstable state, and at this point I do not see solutions that do not require nested transactions. I wrote a simple pseudo code that illustrates a script similar to what I want to execute:
Dictionary<int, bool> opSucceeded = new Dictionary<int, bool> ();
for (int i = 0; i < 10; i++)
{
try
{
Operation(dbContext, i);
opSucceeded[i] = true;
}
catch
{
}
}
try
{
FinalOperation(dbContext, opSucceeded);
}
catch
{
}
The biggest problem for me: how to ensure that when FinalOperation is completed, all Operation (i) operations that were completed successfully are rolled back? Note that I would also like to ignore the errors of one operation (i).
Is it possible to achieve this using TransactionScope nested objects, and if not, how would you approach this problem?