title: Entity Framework - Condition on one to many join (Lambda)
body: <p>I have 2 entities: Customer &amp; Account, where a customer can have multiple accounts.
  On the account, I have a "PlatformTypeId" field, which I need to condition on (multiple values), among other criterions.
  I'm using Lambda expressions, to build the query. Here's a snippet:</p>
  
  <pre><code>var customerQuery =
      from c in context.CustomerSet.Include("Accounts")
      select c;
  
  if (criterions.UserTypes != null &amp;&amp; criterions.UserTypes.Count() &gt; 0)
  {
      List&lt;short&gt; searchCriterionsUserTypes = 
          criterions.UserTypes.Select(i =&gt; (short)i).ToList();
  
      customerQuery = customerQuery
          .Where(LinqTools.BuildContainsExpression&lt;Customer, short&gt;(
              c =&gt; c.UserTypeId, searchCriterionsUserTypes));
  }
  
  // Other criterions, including the problematic platforms condition (below)
  var customers = customerQuery.ToList();
  </code></pre>
  
  <p>I can't figure out how to build the accounts' platforms condition:</p>
  
  <pre><code>if (criterions.Platforms != null &amp;&amp; criterions.Platforms.Count() &gt; 0)
  {
      List&lt;short&gt; searchCriterionsPlatforms =
          criterions.Platforms.Select(i =&gt; (short)i).ToList();
  
      customerQuery = customerQuery.Where(c =&gt; c.Accounts
          .Where(LinqTools.BuildContainsExpression&lt;Account, short&gt;(
              a =&gt; a.PlatformTypeId, searchCriterionsPlatforms)));
  }
  </code></pre>
  
  <p>(The BuildContainsExpression is a method we use to build the expression for the multi-select)</p>
  
  <p>I'm getting a compilation error: </p>
  
  <p>The type arguments for method 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.</p>
  
  <p>Any idea how to fix this?</p>
  
  <p>Thanks,</p>
  
  <p>Nir.</p>