我目前有以下工作代码.然而,这是非常缓慢的.我知道将所有权作为查询而不是列表传递可能会简化并加快速度,但由于各种原因,这是不可能的.
如何在不创建新列表的情况下更新现有的馆藏列表?其他改进代码的建议?
internal List<DailyHoldingItem> TransformHoldingItemsToCurrency(List<DailyHoldingItem> holdings,string toCurrency)
{
//TODO - how to do this calculation in place, without creating a new list?
var query = (from holding in holdings
from fxRateHolding in amdw.FXRates
from fxRateToCur in amdw.FXRates
where
fxRateHolding.BaseCurrency == holding.Currency &&
fxRateToCur.BaseCurrency == toCurrency &&
fxRateHolding.ValueDate == holding.Date &&
fxRateToCur.ValueDate == holding.Date
select new { holding, fxRateHolding, fxRateToCur });
return query.Select(dhi =>
{
decimal factor = dhi.fxRateToCur.Value / dhi.fxRateHolding.Value;
dhi.holding.MarketValue *= factor;
dhi.holding.Fee *= factor;
dhi.holding.Remuneration *= factor;
return …Run Code Online (Sandbox Code Playgroud)