久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

LINQ to SQL 和并發問題

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
本文介紹了LINQ to SQL 和并發問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我們正在嘗試構建大批量訂單記錄系統.共有三個主要表:1. 訂單2. 訂單詳情3. 訂單發貨

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

發貨表包含每個訂單的 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 異常.在事務中完成提交也無濟于事.我們不能強制 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/update/commit 視為短期的原子操作(即您不會在中間暫停用戶輸入),它應該沒問題.

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.

特別是,使用可序列化的隔離級別,沒有人可以更新您擁有讀鎖的數據(即您查詢的任何內容).唯一的問題是,如果不同的查詢以不同的順序讀取數據,這可能會導致死鎖場景.AFAIK,沒有辦法讓 LINQ-to-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 和并發問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
what does a using statement without variable do when disposing?(處理時不帶變量的 using 語句有什么作用?)
Why doesn#39;t TransactionScope work with Entity Framework?(為什么 TransactionScope 不適用于實體框架?)
How to dispose TransactionScope in cancelable async/await?(如何在可取消的 async/await 中處理 TransactionScope?)
C#/SQL Database listener(C#/SQL 數據庫偵聽器)
主站蜘蛛池模板: 国内精品久久久久久久影视简单 | 99精品九九 | 新超碰97 | 午夜视频一区 | 久久99精品久久久久久秒播九色 | 国产韩国精品一区二区三区 | 欧美日韩国产一区二区三区 | 国产亚洲精品精品国产亚洲综合 | 日韩一区二区在线播放 | 午夜影院在线 | 久久久夜夜夜 | 免费h在线| 国产精品一二三区在线观看 | 五月综合激情网 | av二区三区| 中文字幕精 | 伊色综合久久之综合久久 | 国产一区久久 | 亚洲一区二区视频 | 天天干天天玩天天操 | 亚洲网站在线播放 | 亚洲精品国产综合区久久久久久久 | 在线视频一区二区三区 | 日韩视频一区二区三区 | 99精品久久久久 | 国产精品3区 | 国产 日韩 欧美 在线 | 天天干 夜夜操 | 涩涩视频在线观看免费 | 欧美一级做性受免费大片免费 | 日韩久久久一区二区 | 欧美xxxx做受欧美 | 久久精品国产久精国产 | 国产精品99久久久久久宅男 | 波多野结衣亚洲 | 精品一区国产 | 青春草在线 | 色999视频 | 欧美高清hd| 国产无人区一区二区三区 | 国产日韩精品在线 |