title: How to use method-based queries with lambda expressions
body: <p>I want to join two tables with lambda expressions: Order and OrderLogistics.</p>
  
  <p>Order looks like this: </p>
  
  <pre><code>public class Order{
      public int ID { get; set; }
  }
  </code></pre>
  
  <p>And OrderLogistics looks like this:</p>
  
  <pre><code>public class OrderLogistics{
      public int ID { get; set; }
      public int OrderID { get; set; }
  }
  </code></pre>
  
  <p>I want to join them with Order.ID and OrderLogistics.OrderID.</p>
  
  <p>I do not understand how the queries in this question will be used. <a href="https://stackoverflow.com/questions/5038288/lambda-expression-for-join">Lambda Expression for join</a></p>
  
  <p>The only way of writing a query I know is:</p>
  
  <pre><code>IQueryable&lt;Order&gt; listOfRecentOrders = Orders
      .Where(x =&gt; x.OrderLogistics.DepartureDate == date
      &amp;&amp; x.TypeID != 4
      &amp;&amp; x.TypeID != 5
      &amp;&amp; x.StatusID != 8
      &amp;&amp; x.StatusID != 9
      &amp;&amp; x.StatusID != 10
      &amp;&amp; x.Customer.ID != null
      &amp;&amp; x.IsDeleted == false
      &amp;&amp; x.OrderLogistics.DepartureTime &gt;= 100
      &amp;&amp; x.OrderLogistics.DepartureTime &lt;= 2400)
      .OrderBy(x =&gt; x.OrderLogistics.DepartureTime)
      .Take(8));
  </code></pre>
  
  <p>I do not get what they are doing with a 'var query'. How do I use that in MVC?
  The above method is inside my repository and the result will be passed on to the controller.</p>
  
  <p>So what I want is a query where I can use properties of Order AND properties of OrderLogistics. My own query above doesn't work because the relationship "x.OrderLogistics" does not exists.</p>
  
  <p><strong>EDIT:</strong>
  And I have: </p>
  
  <pre><code>IQueryable&lt;Order&gt; listOfRecentOrders = 
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>var joined2 = from p in Order
      join pType in OrderLogistics
      on p.ID equals pType.OrderID
      select (x =&gt; x.Order);
  </code></pre>
  
  <p>How do I assign joined2 to listOfRecentOrders? I don't see this ANYwhere in all query questions. This is the MOST important part.</p>
  
  <p><strong>PROBLEM:
  <em>I need to do a query where I JOIN two tables. This I want to put inside a list and pass this list to the controller so I can use the data in my view.</em></strong></p>