更新时间:2023-02-18 18:52:57
在原来的查询,这些电话以Enumerable.Join使用幕后一个哈希表,使事情很快。如果切换到。凡,你没有得到这些哈希的好处。您可以使用明确散列来获得同样的效果。
In the original query, those calls to Enumerable.Join are using a hashtable behind the scenes to make things fast. If you switch to .Where, you don't get those hash benefits. You can use hashing explicitly to get the same effect.
ILookup<int, string> deskNameLookup = tradingDesks.Values
.ToLookup(
d => d.Id,
d => d.Name
);
ILookup<int, ProductInfo> infoLookup = ProductInfos.Values
.ToLookup(p.RiskBookId);
foreach(b in books.Values)
{
foreach(dName in deskNameLookup[b.TradingDeskId])
{
foreach(p in infoLookup[b.Id].Concat(infoLookup[0]))
{
var x = new {p, Book = b.Name, TradingDeskName = dName};
}
}
}