Linq to SQL 原子操作集
我想确保 var a 在检索它和对 var b 执行更新之间没有更改。
var a = from item in....
if (a > 100) {
var b = from item in...
b.something = 100;
db.SubmitChanges()
}
我该怎么做呢?我是否只是将其包装在 TransactionScope 中?
I would like to ensure that var a has not changed 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linq 2 sql 专为开箱即用的乐观并发而设计(您想要的是悲观并发)
http://msdn.microsoft.com/en-us/library/bb399373。 aspx
由于锁定可能会出现死锁等情况,我认为您最好坚持乐观并处理冲突解决方案。否则,请查看此处:LINQ to SQL 和并发问题
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