My entity have collection of other entities,
public abstract class CounterMeasurmentPoint : MeasurmentPoint
{
public ICollection<CounterMeasurmentPointValue> CounterMeasurmentPointValues { get; set; }
public CounterMeasurmentPointValue GetLastNotErrorValue()
{
return CounterMeasurmentPointValues.Where(p => p.IsError == false).OrderByDescending(p=>p.DateTime).FirstOrDefault();
}
}
Every next value depends on previous.
var lastValue=GetLastNotErrorValue();
var newValue=CalculateNewValue(lastValue,newValueParameters)
It is very slowly to load all values every time i want to add new item, now i do like that
_counterMeasurePointRepository.GetAll()
.Select(r => new {
MeasurePont = r,
Values = r.CounterMeasurmentPointValues.Where(p => p.IsError == false).OrderByDescending(p=>p.DateTime).Take(1)
})
.ToList().Select(p => p.MeasurePont).ToList()
Is there is any more elegant way to filter nested collection?