title: Entity Framework efficient query filter
body: <p>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:</p>
  
  <pre><code>PagedList&lt;Dress&gt; GetDressesPage&lt;TKey&gt;(int page, int dressesPerPage, Func&lt;Dress, bool&gt; selection, Func&lt;Dress, TKey&gt; order, SortDirection direction);
  </code></pre>
  
  <p>and the way in which I get the products is: </p>
  
  <pre><code>dresses = _context.Dresses.Where(selection).OrderBy(order).Skip(page * dressesPerPage).Take(dressesPerPage).ToList();
  </code></pre>
  
  <p>The problem is with the function <strong>selection</strong>. 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. </p>
  
  <p>Do you know a simpler way in which I could pass a filter as a parameter?</p>