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

LINQ to SQL 和并發(fā)問(wèn)題

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發(fā)問(wèn)題)
本文介紹了LINQ to SQL 和并發(fā)問(wèn)題的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我們正在嘗試構(gòu)建大批量訂單記錄系統(tǒng).共有三個(gè)主要表:1. 訂單2. 訂單詳情3. 訂單發(fā)貨

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

發(fā)貨表包含每個(gè)訂單的 n 條記錄,任何記錄發(fā)貨條目都可以在客戶(hù)接受訂單之前更改,之后訂單將被凍結(jié).(業(yè)務(wù)需求)

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)

雖然這在現(xiàn)實(shí)世界中可能不會(huì)發(fā)生......在我們的負(fù)載測(cè)試期間,我們收到 System.Data.Linq.ChangeConflictException 異常.在事務(wù)中完成提交也無(wú)濟(jì)于事.我們不能強(qiáng)制 LINQ 在更新操作的整個(gè)持續(xù)時(shí)間內(nèi)鎖定該行嗎?

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?

有沒(méi)有其他方法可以解決這個(gè)問(wèn)題?

Is there any other way to get over this?

推薦答案

如果您對(duì)同一數(shù)據(jù)的并發(fā)更新有真正的問(wèn)題,那么您可以考慮在事務(wù)中執(zhí)行整個(gè)操作 - 即獲取數(shù)據(jù) 提交它.只要您將 get/update/commit 視為短期的原子操作(即您不會(huì)在中間暫停用戶(hù)輸入),它應(yīng)該沒(méi)問(wèn)題.

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.

特別是,使用可序列化的隔離級(jí)別,沒(méi)有人可以更新您擁有讀鎖的數(shù)據(jù)(即您查詢(xún)的任何內(nèi)容).唯一的問(wèn)題是,如果不同的查詢(xún)以不同的順序讀取數(shù)據(jù),這可能會(huì)導(dǎo)致死鎖場(chǎng)景.AFAIK,沒(méi)有辦法讓 LINQ-to-SQL 發(fā)出 (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 都可以,只要它們被設(shè)置為可序列化隔離(這是 TransactionScope 的默認(rèn)設(shè)置).

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

這篇關(guān)于LINQ to SQL 和并發(fā)問(wèn)題的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Yield return from a try/catch block(try/catch 塊的收益回報(bào))
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務(wù)的 SqlCommand 時(shí),我應(yīng)該調(diào)用 Parameters.Clear 嗎?)
what does a using statement without variable do when disposing?(處理時(shí)不帶變量的 using 語(yǔ)句有什么作用?)
Why doesn#39;t TransactionScope work with Entity Framework?(為什么 TransactionScope 不適用于實(shí)體框架?)
How to dispose TransactionScope in cancelable async/await?(如何在可取消的 async/await 中處理 TransactionScope?)
C#/SQL Database listener(C#/SQL 數(shù)據(jù)庫(kù)偵聽(tīng)器)
主站蜘蛛池模板: 亚洲男人天堂 | 免费av一区 | 欧美视频一区二区 | 亚洲精品中文字幕乱码三区91 | 午夜精品久久久久久久99 | 色一情一乱一乱一区91av | 国内久久精品 | 免费a在线 | 9l视频自拍九色9l视频成人 | 成人一区二区视频 | 国产欧美一区二区三区在线看蜜臀 | 国产精品天美传媒入口 | 日韩免费在线视频 | 国产深夜福利 | 日日夜夜草 | 亚洲一级黄色片 | 日本国产精品 | 黄色激情视频在线观看 | 久久青草视频 | 国产成人精品三级麻豆 | 欧美一级黄色大片 | a视频在线观看 | 欧美午夜理伦三级在线观看 | 欧美日韩国产成人 | 国产精品一级 | 香蕉视频在线观看网站 | 国产成人免费观看 | 欧美精产国品一二三区 | 日韩免费在线播放 | 久久精品一区二区三区四区五区 | 国产精品成人免费精品自在线观看 | 国产成人福利 | 欧美91视频| 丁香婷婷六月天 | 成人玩具h视频 | 亚洲一区二区三区视频 | 理论片中文字幕 | 夜夜草av | 亚洲理论片 | 丨国产丨调教丨91丨 | 福利网站在线观看 |