开发者

Transactionscope and deadlocks when using enterprise library

开发者 https://www.devze.com 2023-02-24 12:24 出处:网络
We are using Enterprise Library for data access. One of our methods has a de开发者_StackOverflow社区lete and then an insert, against the same table. This gives a deadlock.

We are using Enterprise Library for data access.

One of our methods has a de开发者_StackOverflow社区lete and then an insert, against the same table. This gives a deadlock.

If we put these inside a transaction scope the deadlock no longer occurs.

Intuitively, it feels like it should be the opposite way around. Can anyone explain why it works like this?


Transaction scope combined with TransactionOptions IsolationLevel = IsolationLevel.ReadUncommitted is equivalent to WITH(NOLOCK) in T-SQL so if the table is not locked the deadlocks don't occur...

using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions(){ IsolationLevel = IsolationLevel.ReadUncommitted }))
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号