title: Using Expression<Func<>> in a LINQ Query
body: <p>I want to define a <code>Func&lt;ProductItemVendor, bool&gt;</code> filter expression named <code>CompareProductItemVendorIds</code>, which can be used throughout my application, mostly within Entity Framework/LINQ queries.</p>
  
  <p>I've learned that in order to be able to use this filter in a LINQ query, I must declare it as <code>Expression&lt;Func&lt;&gt;&gt;</code> instead of just <code>Func&lt;&gt;</code>. I understand the reason for this, and it's easy for me to do this.</p>
  
  <p>But I'm having the following problems using that expression in my queries.</p>
  
  <p>First, code such as:</p>
  
  <pre><code>ProductItem.ProductItemVendors.FirstOrDefault(CompareProductItemVendorIds)
  </code></pre>
  
  <p><em>Note: <code>ProductItem</code> is a database entity, and its <code>ProductItemVendors</code> property is a navigation collection.</em></p>
  
  <p>Produces the error:</p>
  
  <blockquote>
    <p>`Instance argument: cannot convert from 'System.Collections.Generic.ICollection' to 'System.Linq.IQueryable'</p>
  </blockquote>
  
  <p>And second, code such as:</p>
  
  <pre><code>var results = from v in Repository.Query&lt;ProductItemVendor&gt;()
                where CompareProductItemVendorIds(v)
                select v;
  </code></pre>
  
  <p>Produces the error:</p>
  
  <blockquote>
    <p>'CompareProductItemVendorIds' is a 'variable' but is used like a 'method'</p>
  </blockquote>
  
  <p>So I have my nice shiny new <code>Expression&lt;Func&lt;&gt;&gt;</code>. How can I use it in my LINQ queries?</p>