title: Navigate across relationships in EF
body: <p>I'm begginer with EF, so my question is probably basic, but I couldn't find any answer...</p>
  
  <p>I have a SQL Compact DB, from which I generated an entity model via the VS wizard. Everything seems fine, I retrieve all my relationships with the good mapping.</p>
  
  <p>So as I understand from here: <a href="http://msdn.microsoft.com/en-us/library/bb386932(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb386932(v=vs.110).aspx</a> I should be able to do this, "querying across relationships":</p>
  
  <pre><code>IQueryable&lt;Ingredient&gt; IngQuery = from i in db.Ingredient
              where i.Product.ID == ProdID
              select i;
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <blockquote>
    <p>'System.Collections.Generic.ICollection' does not
    contain a definition for 'ID' and no extension method 'ID' accepting a
    first argument of type
    'System.Collections.Generic.ICollection' could be found
    (are you missing a using directive or an assembly reference?).</p>
    
    <p>This error occurs when you try to call a method or access a class member that does not exist</p>
  </blockquote>
  
  <p>However, if I go deeper into the auto-generated code, I can see a public property 'ID' is declared for 'Product', and 'Ingredient' return a collection of 'Product':</p>
  
  <ul>
  <li><p>Ingredient</p>
  
  <pre><code>public partial class Ingredient
  {
      public Ingredient()
      {
          this.Product = new HashSet&lt;Product&gt;();
      }
  
      public string Name { get; set; }
      public int ID { get; set; }
  
      public virtual ICollection&lt;Product&gt; Product { get; set; }
  }
  </code></pre></li>
  <li><p>Product</p>
  
  <pre><code>public partial class Products
  {
      public Products()
      {
          this.Ingredient = new HashSet&lt;T_PROPSTHERAP&gt;();
      }  
      public int ID { get; set; }
      public string Name { get; set; }
      public string Usage { get; set; }
      public byte[] Photo { get; set; }
      public int FK_OrganeProduct { get; set; }
      public int FK_Type { get; set; }
      public virtual OrganeProduct OrganeProduct { get; set; }
      public virtual Type Type { get; set; }
      public virtual ICollection&lt;Ingredient&gt; Ingredient { get; set; }
  }
  </code></pre></li>
  </ul>
  
  <p>But it doesn't work as I expected.</p>
  
  <p>I can use the following as workaround:</p>
  
  <pre><code>List&lt;Ingredient&gt; lstIng = (_oTest.Products
                      .Where(p =&gt; p.Name == (string)lsbProducts.SelectedItem)
                      .SelectMany(p =&gt; p.T_PROPSTHERAP)).ToList();
  </code></pre>
  
  <p>But I don't think it's a smart way to do the trick... And I don't understand what I am missing...</p>
  
  <p>Could anyone help?</p>