title: EF Core Intersect between List and Property of child element returns "ArgumentNullException"
body: <p>I am currently trying to intersect a list of IDs with a child property of my Database Entity.</p>
  <p>The intent of doing so is to find all &quot;Form&quot; records that that have all of the list Ids matching at least one entity in the child entity &quot;Location&quot;.
  I believe the SQL equivalent would be doing an IN on a joined table &quot;Locations&quot;.</p>
  <p>The structure is as such for the element in question: (I have intentionally left out all other properties).</p>
  <pre><code>public class Form
  {
  
      [Column(&quot;FormId&quot;), DatabaseGenerated(DatabaseGeneratedOption.Identity), Key]
      public Guid Id { get; set; }
      public virtual ICollection&lt;Location&gt; Locations { get; set; }
  }
  
  public class Location
  {
      [Column(&quot;LocationId&quot;), DatabaseGenerated(DatabaseGeneratedOption.Identity), Key]
      public Guid Id { get; set; }
  }
  </code></pre>
  <p>I am attempting to do the following:</p>
  <pre><code>var locationIdsL = locationIds.Split(',').Select(Guid.Parse).ToList();
  
  return baseQuery.Include(x =&gt; x.Locations).Where(x =&gt; x.Locations.Select(y =&gt; y.Id).Intersect(locationIdsL).Count() == locationIdsL.Count);
  </code></pre>
  <p>* Assume that the <code>locationIdsL</code> variable is a valid list of Guids.</p>
  <p>The code above returns the following exception:</p>
  <blockquote>
  <p>System.ArgumentNullException: Value cannot be null. (Parameter
  'parameter')    at
  System.Linq.Expressions.Expression.Lambda(Expression body, String
  name, Boolean tailCall, IEnumerable`1 parameters)    at
  System.Linq.Expressions.Expression.Lambda(Expression body,
  ParameterExpression[] parameters)    at
  Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ReducingExpressionVisitor.Visit(Expression
  expression)    at
  System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor
  visitor, IArgumentProvider nodes)    at
  System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression
  node)    at
  System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor
  visitor)    at
  System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)</p>
  </blockquote>
  <p>However, if I were to manually consume the collection like so:</p>
  <pre><code>List&lt;Form&gt; forms = new List&lt;Form&gt;();
  foreach (var form in baseQuery.Include(x =&gt; x.Locations))
  {
      var locations = form.Locations;
      if (locations.Select(x =&gt; x.Id).Intersect(locationIdsL).Count() == locationIdsL.Count)
      {
          forms.Add(form);
      }
  }
  </code></pre>
  <p>The <code>forms</code> collection gets the item that I expect to see, most notably, with no exception.</p>
  <p>For obvious reasons the latter is not an acceptable solution as it would require the loading of the entire dataset.</p>
  <p>I am not sure what I am missing here as EFCore should be able to translate the first query.</p>
  <p>In all honesty, my approach may be wrong entirely and my I might be &quot;anti-patterning&quot; my query entirely, I am not sure; any suggestions are welcome.</p>