In Domain Model there are usually quite huge entity trees and sometimes some filtering is needed.
I found myself writing following method:
public virtual HorseStatistics GetStatistics(int year)
{
foreach (HorseStatistics statistic in this.HorseStatistics)
{
if (statistic.Year.Equals(year))
return statistic;
}
return null;
}
This method is in object Horse and contains list of HorseStatistics with unique property Year.
With some help from .NET 3.5 I have this:
horse.HorseStatistics.Find(x => x.Year == 1999);
Just think how my first method look like if I want to do this:
horse.HorseStatistics.Find(x => x.Year == 1999 && x.FinishedAsFirst == 3 && x.FinishedAsThird == 5);
Actually there are some component based problems with this (I use nHibernate and so my List must be IList), but as seen in source article performance improvement is amazing.
That is a 289200% improvement in performance.
Source.Equals(“realspeedyobjectfiltering”);