title: Enumerable Intersect and Any Expressions do not compile to SQL
body: <p>I'm trying to create an extension method for IQueryable which gets a function returning a <code>IEnumerable&lt;Int32&gt;&gt;</code> as an input parameter, which should be checked against another constant list of numbers. If at least one identical entry is contained in both lists it should return true, something like <code>listA.Intersect(listB).Any()</code>. This expression also has to compile well to SQL (latest EF core) (<code>Intersect()</code> and <code>Any()</code> themselves should do). So here is what I came up with (yet):</p>
  <pre class="lang-cs prettyprint-override"><code>public static IQueryable&lt;T&gt; AuthorizedRecords&lt;T&gt;(this IQueryable&lt;T&gt; query, Expression&lt;Func&lt;T, IEnumerable&lt;Int32&gt;&gt;&gt; employeeIds)
  {
      var ids = (new List&lt;int&gt; { 1, 2, 3 }).AsEnumerable(); // &lt;- replaced later
      
      var methodAny = typeof(Enumerable)
          .GetMethods()
          .Where(m =&gt; m.Name == &quot;Any&quot; &amp;&amp; m.GetParameters().Length == 1)
          .First()
          .MakeGenericMethod(typeof(int));
  
      var methodIntersect = typeof(Enumerable)
           .GetMethods()
           .Where(m =&gt; m.Name == &quot;Intersect&quot; &amp;&amp; m.GetParameters().Length == 2)
           .First()
           .MakeGenericMethod(typeof(int));
  
      var lambdaParam = employeeIds.Parameters.Single();
      var lambda = Expression.Lambda(
          Expression.Call(
              methodAny,
              Expression.Call(
                  methodIntersect,
                  Expression.Constant(ids), 
                  employeeIds.Body
              )
          ),
          lambdaParam
       );
       
       var predicate = (Expression&lt;Func&lt;T, bool&gt;&gt;)lambda;
       return query.Where(predicate);
  }       
  </code></pre>
  <p>This code compiles but I get a runtime error that <em>The LINQ expression &lt;...very long expression...&gt; cannot be translated to sql</em>. What's wrong with the expression?</p>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>The expression seems to be fine, instead the <code>Intersect()</code> method fails for some reason. I reduced the code to this minimal Linq query reproducing the error:</p>
  <pre class="lang-cs prettyprint-override"><code>dbContext.Meetings
    .Where(e =&gt; e.AccessList
      .Select(x =&gt; x.Id)
      .Intersect((new List&lt;int&gt;() { 90, 91, 92 })
      .Any()
    );
  </code></pre>
  <p>Now I get a <em>System.ArgumentNullException: Value cannot be null. bei System.Linq.Expressions.Expression.Lambda(Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)</em></p>
  <p>What could be the problem with the Intersect query?</p>