title: Can I use an extension method in Entity Framework SubQuery?
body: <p>I'm trying to consolidate logic for accessing different tables using Entity Framework. I created an extension method for pulling all registrations from my registration entity where the person is attending:</p>
  
  <pre><code>public static IEnumerable&lt;Registration&gt; Attending(this IEnumerable&lt;Registration&gt; registrations)
  {
      return registrations.Where(r =&gt; r.Status == RegistrationStatus.Paid || r.Status == RegistrationStatus.Assigned || r.Status == RegistrationStatus.Completed);
  }
  </code></pre>
  
  <p>This works great for queries like this:</p>
  
  <pre><code>var attendees = db.Registrations.Attending().ToList();
  </code></pre>
  
  <p>But it doesn't work when used in a subquery:</p>
  
  <pre><code>ProductTotals = db.Products.Where(p =&gt; p.EventID == ev.Id).Select(p =&gt; new ProductSummaryViewModel
  {
      ProductID = p.ProductID,
      ProductName = p.Name,
      Registrations = p.Registrations.Attending().Count(),
  }).ToList();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method
    'System.Collections.Generic.IEnumerable<code>1[Registration]
    Attending(System.Collections.Generic.IEnumerable</code>1[Registration])'
    method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>Is there any way re-use that code in a subquery?</p>