LINQ to SQL和并发问题

编程入门 行业动态 更新时间:2024-10-18 22:30:53
本文介绍了LINQ to SQL和并发问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们正在努力建设一个大批量定单记录系统。 有三个主要的表: 1.订单 2.订单明细 3. OrderShipment

We are trying to build a High-Volume Orders Record System. There are three primary tables: 1. Orders 2. OrderDetails 3. OrderShipment

shipment表中包含每个订单的任何记录货物入口N记录可以在客户接受阶之前,被冻结后进行更改。 (业务需求)

The Shipment table contains n record per order and any record shipment entry can be changed before the Customer accepts th order, after which it is frozen. (A business requirement)

虽然这可能在现实世界的场景在我们的负载测试中没有发生...... ,我们正在将System.Data.Linq。 ChangeConflictException例外。 结束语提交内部transacion没有任何帮助。 不能强迫我们LINQ获得该行的锁更新操作的整个过程?

Although this may not happen in real world scenarios... during our load tests, we are getting System.Data.Linq.ChangeConflictException exceptions. Wrapping up the submit inside a transacion is not helping either. Can't we force LINQ to get a lock on the row for the entire duration of the update operation?

是否有任何其他的方式来渡过这个?

Is there any other way to get over this?

推荐答案

如果您有相同的数据并发更新真正的问题,那么你可以考虑在执行整个操作交易 - 即获取数据的和的承诺吧。只要你对待GET /更新/提交一个短命的,原子操作(即你没有暂停在中间用户输入)应该没问题。

If you are having genuine issues with concurrent updates on the same data, then you might consider performing the entire operation in a transaction - i.e. getting the data and committing it. As long as you treat the get/update/commit as a short-lived, atomic operation (i.e. you don't pause for user-input in the middle) it should be OK.

在特定的,具有序列化隔离级别,没有人可以更新你有(你质疑,即任何事情)一个读锁定数据。唯一的问题是,这可能会导致不同的,如果查询读取不同的订单数据死锁的情况。据我所知,有没有办法让LINQ到SQL发出(UPDLOCK)暗示,这是一种耻辱。

In particular, with a serializable isolation level, nobody can update data that you have a read lock on (i.e. anything you have queried). The only problem is that this might lead to deadlock scenarios if different queries are reading data in different orders. AFAIK, there is no way to get LINQ-to-SQL to issue the (UPDLOCK) hint, which is a shame.

无论是一个TransactionScope或的SqlTransaction会做,只要它们被设置为可序列化隔离(这是TransactionScope的默认值)。

Either a TransactionScope or a SqlTransaction would do, as long as they are set as serializable isolation (which is the default for TransactionScope).

更多推荐

LINQ to SQL和并发问题

本文发布于:2023-10-26 18:43:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LINQ   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!