views:

140

answers:

1

I'm facing the next problem. I have a piece of code that goes like this:

DoSomething(){
  using (TransactionScope scope = new TransactionScope())
    {
      InsertSomething();
      InsertSomethingElse();
      InsertYetAnotherThing();
      ProcessDataRelatedWithThePreviousInserts();
      scope.Complete()
    }
}

In ProcessDataRelatedWithThePreviousInserts I check for a condition and if needed, the rest of the work flow is redirected to a Message Queue in other server. In the other server, I recover the message, and continue the workflow (basically, make some other insertions that are related with the ones on the DoSomething method).

This is in theory, because I only manage to do that if I remove the TransactionScope in the DoSomething method. Is there a way to accomplish what I want to do or I'll need to change the way the transactions are handled?

A: 

Did you already try

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    // ...
    using (TransactionScope innerscope = new TransactionScope(TransactionScopeOption.Supress)
    {
        ProcessDataRelatedWithThePreviousInserts();
    }
    scope.Complete();
}

explicitly supressing the outer transaction for your call to ProcessDataRelatedWithThePreviousInserts().

Filburt