Enginerds

11/01/2009

Business object filtering

Filed under: Uncategorized — Mart Leet @ 12:59

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”);

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.