LINQ to SQL 结合未提交读和已提交读

发布于 2024-12-03 07:50:58 字数 375 浏览 1 评论 0原文

我想使用 LINQ to SQL 作为应用程序的数据层。乐观并发似乎会起作用,但我想过于乐观,不去理会任何锁定(例如 ReadUncommissed 又名 WITH (NOLOCK)),直到我得到到 SubmitChanges(),此时我认为使用 ReadComfilled 就可以了。

这听起来很疯狂吗?是否最好使用两个分离的 TransactionScope 对象(一个用于使用 ReadUncommissed 进行读取,第二个用于使用 ReadCommited 提交更改),或者是有没有更好的方法可以在提交更改之前立即提高隔离级别?

I'd like to use LINQ to SQL as the data layer for an application. Optimistic concurrency seems like it would work, but I'd like to be over-optimistic and not bother with any locking (e.g. ReadUncommitted a.k.a. WITH (NOLOCK)) until I get to SubmitChanges(), at which point I think it's OK to use ReadCommitted.

Does this sound like madness? Is it better to use two disjunct TransactionScope objects (one for reading with ReadUncommitted, followed by a second for submitting changes with ReadCommitted), or is there some nicer way I can raise the isolation level immediately before submitting changes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-12-10 07:50:58

ReadCommitedReadUncommissedSubmitChanges() 上并不重要,因为它是写入,而不是读取。无论隔离级别是什么,更新始终会获取锁并尊重现有锁。必须如此,这就是锁的主要目的。

当然,通过更新未提交的数据,您将面临记录甚至不存在、无法更新的风险,但这是您在决定乐观时接受的风险。

ReadCommitted or ReadUncommitted does not matter on a SubmitChanges() because it is a write, not a read. No matter what the isolation level, an update always acquires a lock and respects existing locks. It has to, that is the main purpose of locks.

Of course, by updating uncommitted data you run the risk that the record does not even still exist to be updated, but that was the risk you accepted when deciding to be optimistic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文