title: Entity Framework Select Query
body: <p>I have the following classes:</p>
  
  <pre><code>public class Seller : Entity
  {
      public int SellerId { get; set; }
      public string Name { get; set; }
  
      public ICollection&lt;InventoryItem&gt; InventoryItems { get; set; }
  }
  
  public class InventoryItem : Entity
  {
      public int InventoryId { get; set; }
      public int SellerId { get; set; }
      public string SellerSku { get; set; }
  
      public ICollection&lt;SiteInventoryItem&gt; SiteInventoryItems { get; set; }
  }
  
  public class SiteInventoryItem : Entity
  {
      public int Id { get; set; }
      public int InventoryId { get; set; }
      public SiteType Site { get; set; }
  }
  </code></pre>
  
  <p>So a <code>Seller</code> has a collection of <code>InventoryItem</code> which in turn have a collection of <code>SiteInventoryItem</code>.</p>
  
  <p>How do I get a <code>Seller</code> with a list of <code>InventoryItems</code> that have a list of <code>SiteInventoryItems</code> where the <code>SiteType == SiteType.SiteName</code> and the <code>Seller.SellerId == 14</code>?</p>
  
  <p>The <code>SiteType</code> is an <code>Enum</code> and the db type is <code>int</code>.</p>
  
  <p>I have tried the following and it compiles and runs, but the result is not what is expected:</p>
  
  <pre><code>var seller = repo.Query(
                  x =&gt; x.InventoryItems,
                  x =&gt; x.InventoryItems.Select(y =&gt; y.SiteInventoryItems)
              ).Select(x =&gt; new
              {
                  Seller = x,
                  InventoryItems = x.InventoryItems,
                  SiteInventoryItems = x.InventoryItems.Select(y =&gt; new
                  {
                      InventoryItem = y,
                      SiteInventoryItems = y.SiteInventoryItems.Where(z =&gt; z.Site == SiteType.Amazon)
                  })
              }).Where(x =&gt; x.Seller.SellerId == 14).First();
  </code></pre>