title: Reusable predicate expressions in LINQ to Entities queries
body: <p>A certain set of criteria that occurs in many different queries throughout our application has slowly grown more complex. To avoid duplication of this code, I want to split these criteria out into a method that returns the conditions as an <strong>Expression</strong> that can in turn be applied where necessary:</p>
  
  <pre><code>public Expression&lt;Func&lt;Invoice, bool&gt;&gt; GetComplexPredicate()
  {
      // complex predicate is returned as an Expression:
      return c =&gt; ...
  }
  </code></pre>
  
  <p>Reused as such:</p>
  
  <pre><code>var result = repository.Invoice.Where(GetComplexPredicate())
  </code></pre>
  
  <p>However, the statement below won't compile, since <strong>c.Invoice</strong> is just an <strong>ICollection</strong>.</p>
  
  <pre><code>var result = repository.Customer
      .Where(c =&gt; c.Country == "US" &amp;&amp; c.Invoice.Any(GetComplexPredicate()))
  </code></pre>
  
  <p>Is it in any way possible to use the expression like this?</p>