LINQ to SQL和并发问题 [英] LINQ to SQL and Concurrency Issues

查看:245
本文介绍了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和并发问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆