如果我得到您的漂移,请尝试以下操作:
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 _
})