title: LINQ to Entities does not recognize the method 'System.Linq.IQueryable in nested select
body: <p>I wrote an extension method to get only approved absences out of a list of absences:</p>
  
  <pre><code>public static IQueryable&lt;tblAbwesenheit&gt; OnlyApprovedAbsences(this IQueryable&lt;tblAbwesenheit&gt; source)
  {
      return source.Where(a =&gt;
          (a.tblAbwesenheitsantraggenehmigungs.Any() &amp;&amp; a.tblAbwesenheitsantraggenehmigungs.All(g =&gt; g.AbwesenheitsgenehmigungsstatusID == AbsenceStatusIds.Approved))
          &amp;&amp; (!a.tblAbwesenheitsstornierunggenehmigungs.Any() || a.tblAbwesenheitsstornierunggenehmigungs.Any(g =&gt; g.AbwesenheitsgenehmigungsstatusID != AbsenceStatusIds.Approved)));
  }
  </code></pre>
  
  <p>When I'm using this method with a "normal" Select, everything is fine:</p>
  
  <pre><code>context.tblAbwesenheits.OnlyApprovedAbsences().ToList()
  </code></pre>
  
  <p>However when I'm using it inside a Select statement, I get an error:</p>
  
  <pre><code>context.tblMitarbeiters.Select(m =&gt; new
  {
      Employee = m,
      AbsencesForEmployee = m.tblAbwesenheits.OnlyApprovedAbsences()
  })
  .ToList();
  </code></pre>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method
    'System.Linq.IQueryable<code>1[Data.tblAbwesenheit]
    OnlyApprovedAbsences(System.Linq.IQueryable</code>1[Data.tblAbwesenheit])'
    method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>I have searched quite a lot, but could not find a way to teach Entity Framework to recognize my Method without expanding the query to</p>
  
  <pre><code>context.tblMitarbeiters.Select(m =&gt; new
  {
      Employee = m,
      AbsencesForEmployee = m.tblAbwesenheits
          .Where(a =&gt;
              (a.tblAbwesenheitsantraggenehmigungs.Any() &amp;&amp; a.tblAbwesenheitsantraggenehmigungs.All(g =&gt; g.AbwesenheitsgenehmigungsstatusID == AbsenceStatusIds.Approved))
              &amp;&amp; (!a.tblAbwesenheitsstornierunggenehmigungs.Any() || a.tblAbwesenheitsstornierunggenehmigungs.Any(g =&gt; g.AbwesenheitsgenehmigungsstatusID != AbsenceStatusIds.Approved)))
  })
  .ToList();
  </code></pre>
  
  <p>Is there a way to get EF to recognize my Method?</p>