Bon*_*arp 13 .net c# sql entity-framework
我想了解TransactionScopeOption.RequiresNew
在EntityFramework(w/Sql Server 2008)上使用的交易/缺点是什么,我们不应该RequiresNew
总是使用的原因是什么.
问候.
Rem*_*anu 23
您应该使用Required
没有RequiresNew
.RequiresNew意味着每个操作都将使用新事务,即使存在包含已存在的事务范围.这肯定会导致僵局.即使Required
存在另一个严重的问题TransactionScope
,即它默认创建一个Serializable
事务,这是一个非常糟糕的选择,也是死锁地狱的另一个捷径,没有可扩展性.请参阅使用新的TransactionScope()认为有害.您应该始终使用显式TransactionOption
设置隔离级别来创建事务范围ReadCommitted
,这是一个更加理智的隔离级别:
using(TransactionScope scope = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions {
IsolationLevel = IsolationLevel.ReadCommitted}))
{
/// do work here
...
scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9714 次 |
最近记录: |