久久久久久久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 數據庫偵聽器)
主站蜘蛛池模板: japanhd成人| 欧美视频一区二区三区 | 国产精品免费在线 | 国产情品 | 久久久www成人免费精品张筱雨 | 中文字幕av一区二区三区 | 麻豆国产一区二区三区四区 | 久草在线高清 | 国产农村一级国产农村 | 成人免费看片又大又黄 | 日韩美女一区二区三区在线观看 | 久久久久国产精品 | 99热首页 | 亚洲一二三视频 | www.中文字幕.com| 99精品在线观看 | 中文字幕在线视频一区二区三区 | 日韩在线视频播放 | 伦理午夜电影免费观看 | 亚洲自拍偷拍欧美 | 亚洲精品1 | 精品国产视频 | 另类在线 | 色欧美综合 | 夜夜爽99久久国产综合精品女不卡 | 国产精品夜夜夜一区二区三区尤 | 日韩欧美大片在线观看 | 久久一区二区三区免费 | 国产精品视频在线观看 | 亚洲入口 | 国产精品免费一区二区三区 | 国产一区二区久久久 | 黄色毛片在线观看 | 国产欧美一区二区三区在线看蜜臀 | 在线观看视频91 | 日本中文字幕在线视频 | 二区成人| 亚洲综合无码一区二区 | 亚洲欧美精品国产一级在线 | 国产精品99久久久久久久久久久久 | 男女视频免费 |