.net 了解 TransactionScopeOptions:RequiresNew = Suppress + Required?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6987862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding TransactionScopeOptions: RequiresNew = Suppress + Required?
提问by Jaxidian
I believe I understand TransactionScopeOption.Suppressand TransactionScopeOption.Requiredbut am having difficulty understanding what TransactionScopeOption.RequiresNewdoes. 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 RequiresNewmeans?
我相信我理解TransactionScopeOption.Suppress,TransactionScopeOption.Required但我很难理解TransactionScopeOption.RequiresNew它的作用。根据我读到的最后一个解释,以下两个代码块在功能上是否相同?这是什么RequiresNew意思的准确表示?
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
}
采纳答案by Eddy
To get a good understanding of the transaction scopes you can read this msdn article
要更好地了解事务范围,您可以阅读这篇 msdn 文章
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".
除了创建的嵌套范围的数量不同之外,我找不到一个很好的解释这两者有何不同。无论交易是否已经存在,这两种情况都应该导致相同数量的交易。我找不到可以参考的好资源,但我总是会选择 RequiresNew,而不是组合的 Suppress/Required。RequiresNew 的基本意思是:“无论是否已经有交易,都给我一个新的交易”。
Update:In case the first link remains broken you can find it in the wayback archive here
更新:如果第一个链接仍然损坏,您可以在此处的回溯档案中找到它

