I want to iterate through each object in a collection and then update a property on each object with another array collection
My use case is I have some entities which I initially read from my collection into an array, and perform some complex calculation and then update back my original collection.
public void WhatIfCalculation(string Product, string SiteID, System.Linq.IQueryable<DAL.OMS_StockStatus> prodStatus, ref System.Linq.IQueryable<PivotViewModel> activityInfo)
{
var sff = activityInfo.Where(a => a.Activity == "System Forecast" && a.SiteID == SiteID).ToList();
aSFF = new double?[sff.Count()];
for (int i = 0; i < sff.Count(); i++)
{
aSFF[i] = sff.ElementAt(i).Value + 1;
}
var prf = activityInfo.Where(a => a.Activity == "Planned Receipts" && a.SiteID == SiteID).ToList();
aPRF = new double?[prf.Count()];
for (int i = 0; i < prf.Count(); i++)
{
aPRF[i] = prf.ElementAt(i).Value + 2;
}
// Will perform some calculation here. And then update back my collection.
for (int i = 0; i < aSFF.Length; i++)
{
activityInfo.Where(a => a.Activity == "System Forecast" && a.SiteID == SiteID).ToList().ElementAt(i).Value = aSFF[i];
}
for (int i = 0; i < aPRF.Length; i++)
{
activityInfo.Where(a => a.Activity == "Planned Receipts" && a.SiteID == SiteID).ToList().ElementAt(i).Value = aPRF[i];
}
}
But above update is not updating my collection. When I browse back through my activityInfo - its still showing original value.