开发者

Linq to SQL atomic set of operations

开发者 https://www.devze.com 2023-04-06 21:14 出处:网络
I would like to ensure that var a has not cha开发者_JS百科nged between retrieving it and performing the update on var b.

I would like to ensure that var a has not cha开发者_JS百科nged between retrieving it and performing the update on var b.

var a = from item in....

if (a > 100) {
    var b = from item in...
    b.something = 100;
    db.SubmitChanges()
}

How would I go about doing this? Do I just wrap the thing in a TransactionScope?


Linq 2 sql is designed for optimistic concurrency out of the box (what you want is pessimistic) http://msdn.microsoft.com/en-us/library/bb399373.aspx

Due to possible deadlocks etc. with locking, I think you better stick to optimistic and handle the conflict resolution. Otherwise, have a look here: LINQ to SQL and Concurrency Issues

0

精彩评论

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