title: EF 7 Include a collection with where clause and then a collection one level down
body: <p>I am trying to query a collection and child collection using EF 7. Here's the code:</p>
  
  <pre><code>var customerID = 86795;
  var query = await _context.Contacts
              .Where(g =&gt; g.CustomerID == customerID )
              .Include(g =&gt; g.Address.Where(p =&gt; p.AddressTypeID == 1))
              .ThenInclude(p=&gt; p.City)
              .ToListAsync();
  
  
  &gt; Error CS1061  'IEnumerable&lt;Address&gt;' does not contain a definition for
  &gt; 'City' and no extension method 'City' accepting a first argument of
  &gt; type 'IEnumerable&lt;Address&gt;' could be found (are you missing a using
  &gt; directive or an assembly reference?)  Contacts.DNX 4.5.1, Contacts.DNX
  &gt; Core 5.0
  </code></pre>
  
  <p>It works fine when I just use</p>
  
  <pre><code>var customerID = 86795;
  var query = await _context.Contacts
              .Where(g =&gt; g.CustomerID == customerID )
              .Include(g =&gt; g.Address)
              .ThenInclude(p=&gt; p.City)
              .ToListAsync();
  </code></pre>
  
  <p>But this will load all the addresses for the customer where I only want the recent address for which the AddressTypeID is 1.</p>
  
  <p>Any idea how to do this?</p>