In my mvc site I use EF 4.1 for data access . Now I develop product search functionality. The method signature for getting filtered products is:
PagedList<Dress> GetDressesPage<TKey>(int page, int dressesPerPage, Func<Dress, bool> selection, Func<Dress, TKey> order, SortDirection direction);
and the way in which I get the products is:
dresses = _context.Dresses.Where(selection).OrderBy(order).Skip(page * dressesPerPage).Take(dressesPerPage).ToList();
The problem is with the function selection. I would like to be able to construct that by appending different conditions. Now I am constructing that using some if clauses for each combination of parameters ... but that gets too complex.
Do you know a simpler way in which I could pass a filter as a parameter?