I believe I understand TransactionScopeOption.Suppress
and TransactionScopeOption.Required
but am having difficulty understanding what TransactionScopeOption.RequiresNew
does. Based on the last explanation that I read, would the following two blocks of code functionally be the same? Is this an accurate representation of what RequiresNew
means?
using (var ts1 = new TransactionScope(TransactionScopeOption.RequiresNew))
{
DoStuff();
ts1.Complete();
}
and
using (var ts2 = new TransactionScope(TransactionScopeOptions.Suppress))
{
using (var ts3 = new TransactionScope())
{
DoStuff();
ts3.Complete();
}
ts2.Complete(); // not required but recommended for consistency's sake
}
To get a good understanding of the transaction scopes you can read this msdn article
I can't find a good explanation how those two would be different except that the number of nested scopes that are created are different. Both cases should lead to the same amount of transactions regardless if a transaction already exists or not. I can't find a good resource to refer to but I would always go for RequiresNew over a combined Suppress/Required. RequiresNew basically means: "regardless if there already is or isn't a transaction give me a new one".
Update: In case the first link remains broken you can find it in the wayback archive here