title: Query many to many relation with lambda expression
body: <p>I'm using entity framework database first.</p>
  
  <p>For one to many relation, in sql server, I use the following sql query(Status_ID is foreign key):</p>
  
  <pre><code>SELECT Products.*, Status.Title as Pstatus
  FROM Products, Status 
  WHERE Products.Status_ID = Status.ID
  </code></pre>
  
  <p>In MVC I use the following code to retrieve the same data as above sql query and pass the list to the View:</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>var products = oDB.Products.Include(m =&gt; m.Status)
                         .ToList();
  // string test = products[0].Status.Title;
  return View(products);
  </code></pre>
  
  <p>In the view I can access the desired data by the following code:</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@model List&lt;myDB.Product&gt;
  ...
  @item.Status.Title // This works well for each item in the list
  </code></pre>
  
  <hr>
  
  <p>For MANY TO MANY RELATIONS WITH JUNCTION TABLE, this is my .edmx:</p>
  
  <p><a href="https://i.stack.imgur.com/O0qtJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O0qtJ.png" alt="enter image description here"></a></p>
  
  <p>Now How could I retrieve list of products including related categories?
  I need the list of products and pas it to the view as a list, and access each product's categories in the view.</p>
  
  <p>My Classes (These classes are generated automatically):</p>
  
  <pre><code>public partial class Category
  {
      public int ID { get; set; }
      public string Title { get; set; }
      public virtual ICollection&lt;Products_Categories&gt; Products_Categories { get; set; }
  }
  
  public partial class Products_Categories
  {
      public int ID { get; set; }
      public Nullable&lt;int&gt; Product_ID { get; set; }
      public Nullable&lt;int&gt; Category_ID { get; set; }
      public virtual Category Category { get; set; }
      public virtual Product Product { get; set; }
  }
  
  public partial class Product
  {
      public int ID { get; set; }
      public string Title { get; set; }
      public virtual ICollection&lt;Products_Categories&gt; Products_Categories { get; set; }
  }
  </code></pre>