如果我得到你的意思嘗試以下操作:
Dim result = db.InitialCosts _
.GroupJoin(_
db.Depreciations, _
cost => cost.ProductID, _
depr => depr.ProductID, _
(cost,g) => New With { _
.OriginalCost = cost.Cost, _
.DepreciatedCost = g.Aggregate(_
cost.Cost, _
(cost,rate) => cost * (1- rate.DepreciationRate)) _
})
或者如果花費很長的時間一個可以嘗試做的加入本身本地內存:
Dim rawGroups = db.Depreciations _
.ToLookup(depr => depr.ProductID, depr => depr.DepreciationRate)
Dim result = db.InitialCosts _
.Select(_
cost => New With { _
.OriginalCost = cost.Cost, _
.DepreciatedCost = rawGroups.Contains(cost.ProductID) ? _
rawGroups[cost.ProductID].Aggregate(_
cost.Cost, _
(cost,rate) => cost * (1- rate)) _
: cost.Cost _
})
歡迎來到SO。但你有什麼嘗試?你能分享一些你的工作嗎? –