extension methods in linq

public static class MyExtensions
{
    public static IEnumerable SelectWhere(
     this IEnumerable source,
     Func filter)
    {
        var results = new List();

        foreach (var s in source)
            if (filter(s))
                results.Add(s);

        return results;
    }
}


    private double? GetConvertedPrice(RealEstate realEstate)
    {
        return realEstate.Price * exchangeRates[realEstate.PriceCurrencyId.Value - 1].Value;
    }




        var realEstates = _db.RealEstates.SelectWhere(re =>
                                                       (re.CategoryId == null || catId == null || re.CategoryId == catId)
                                                       && (re.TypeId == null || typeId == null || re.TypeId == typeId)
                                                       && (re.CityId == null || cityId == null || re.CityId == cityId)
                                                       && (re.DistrictId == null || districtId == null || re.DistrictId == districtId)
                                                       && (re.Price == null || priceMin == null || GetConvertedPrice(re) >= priceMin)
                                                       && (re.Price == null || priceMax == null || GetConvertedPrice(re) <= priceMax)
            );


http://msdn.microsoft.com/en-us/library/bb383977.aspx

search this blog (most likely not here)