我正在將一些存儲過程轉換爲vb.net linq(SQL to linq ....手動),因爲存儲過程很慢。linq是否阻塞線程?
我在併發線程中使用linq查詢。
運行性能分析後,我發現linq在查詢時似乎鎖定源集合(如下面代碼段中的cache.IPMS_TBL_EL_PRICE_COMPONENT)。
這是真的嗎? linq有沒有(not_lock/lock)選項? 我真的不希望集合被鎖定。它會減慢多線程查詢。
非常感謝。
代碼段:
看到http://imgur.com/Z9vsR或見下文
insert0 = (From PPC In cache.IPMS_TBL_EL_PRODUCT_PRICE_COMPONENT_MAPPING
From PC In cache.IPMS_TBL_EL_PRICE_COMPONENT
Join LK In cache.IPMS_TBL_LOOKUP
On PC.Component_Type_Id Equals LK.Lookup_Id
Where (PC.Component_Id = PPC.Component_Id OrElse PC.Component_Type_Id = CC3_ID) _
AndAlso LK.Commodity_Id = ELE_COMMODITY_ID _
AndAlso LK.Lookup_Type.ToLower = PRICE_COMPONENT_TYPE.ToLower _
AndAlso PPC.Product_Id = IN_PRODUCT_ID _
AndAlso PPC.Price_Type_Id = IN_PRICE_TYPE_ID _
AndAlso PC.Is_Deleted = 0 _
AndAlso LK.Lookup_Id > MINUS_HUNDRED _
AndAlso PC.Component_Id > MINUS_HUNDRED _
AndAlso lookupValues.Contains(LK.Lookup_Value.ToLower) _
AndAlso (Not PC.ISO_Id.HasValue OrElse Not deletedISO.Contains(PC.ISO_Id.Value))
Select New PriceComponents() With {.ComponentID = PC.Component_Id,
.ComponentName = PC.Component_Name,
.ComponentTypeID = PC.Component_Type_Id,
.ComponentTypeName = LK.Lookup_Value,
.Sequence = PC.Sequence,
.OrderSequence = orderSequeceDict(LK.Lookup_Value.ToLower),
.IsMTM = PC.Is_MTM,
.UcapUsageFactorUnitPrice = PC.UCAP_Usage_Factor_UnitPrice,
.Percentage = PERCENTAGE}
).OrderBy(Function(e As PriceComponents) e.OrderSequence).ThenBy(Function(e As PriceComponents) e.Sequence) _
.Distinct(New PriceComponentsComparer_PK_9_Fields).ToList
如果'cache'是一個LINQ to SQL數據上下文,那麼它不應該跨線程共享。 –
讓我們在這裏備份一下......你知道爲什麼存儲過程很慢嗎?這是轉換爲L2S的一個不尋常的原因。 LINQ查詢是否執行您的存儲過程? –
在查詢過程中,有關阻塞(非延遲,同步執行)或什麼被鎖定(阻止多線程使用)的問題?這些是非常不同的事情。 – 2011-10-20 19:26:42