linq 会阻塞线程吗?
我正在将一些存储过程转换为 vb.net linq (SQL 到 linq .... 手动),因为存储过程很慢。
我在并发线程中使用 linq 查询。
运行性能分析后,我发现 linq 在查询时似乎锁定了源集合(如下面代码段中的cache.IPMS_TBL_EL_PRICE_COMPONENT)。
这是真的吗? linq 有 (not_lock/lock) 选项吗? 我真的不希望收藏被锁定。它会减慢多线程查询的速度。
非常感谢。
代码周期:
参见 https://i.sstatic.net/YLlI6.jpg 或参见下文
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
I am turning some stored procedure to vb.net linq (SQL to linq .... manually) because stored procedure is slow.
I am using linq queries in concurrent threads.
After running a performance analyzing, I find out the linq seems to lock the source collection(like cache.IPMS_TBL_EL_PRICE_COMPONENT in the code period below) when querying.
Is it true? Is there a (not_lock/lock) option for linq?
I really don't want the collection to be locked. It will slow the multi-thread query.
Thank you very much.
Code period:
see in https://i.sstatic.net/YLlI6.jpg or see below
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在调用
ToList
,这会导致查询急切地求值(此时此刻)。使用
ToList
,它将迭代返回请求结果的结果集 - 这确实会使用当前线程。您可以通过不调用
ToList
来推迟评估,并且仅在实际需要迭代结果时才进行评估。You are calling
ToList
which causes the query to evaluate eagerly (there and then).With
ToList
, it will iterate over the result set returning the requested results - this will indeed use the current thread.You can defer evaluation by not calling
ToList
and only evaluate when you actually need to iterate over the results.