title: Join two tables to a model with lambda
body: <p>I'm joining 2 tables in my code. And the code seems to work. But when I try a <code>Debug.WriteLine()</code> it is empty. </p>
  
  <p>I have seen solutions. But not with a model.</p>
  
  <pre><code>IQueryable&lt;Order_OrderCart_OrderLogisticsModel&gt; model = repository.Orders
      .Join(
      repository.OrderLogisticss,
      o =&gt; o.ID,
      ol =&gt; ol.OrderID,
      (o, ol) =&gt; new { Order = o, OrderLogistics = ol })
      .Where(x =&gt; x.OrderLogistics.DepartureDate == 40826)
      .Join(
      repository.OrderCarts,
      o =&gt; o.Order.ID,
      oc =&gt; oc.OrderID,
      (o, oc) =&gt; new Order_OrderCart_OrderLogisticsModel { Order = o.Order, Logistics = o.OrderLogistics, Cart = oc })
      .Where(x =&gt; x.Cart.Sealed != false);
  
  foreach (var item in model)
  {
      Debug.WriteLine(item.Cart.Sealed);
      Debug.WriteLine(item.Order.ID);
      Debug.WriteLine(item.Logistics.DepartureDate);
  
  }
  </code></pre>
  
  <p><strong>Question:</strong>
  So my question is what am I doing wrong? I have other code that only has one join and that does work. Only this does not work.</p>
  
  <p>Please do only answer with lambda code. Yes I know original linq is a bit faster but I like to learn lambda.</p>
  
  <p><strong>Update:</strong> </p>
  
  <p>The generated SQL that seems to work fine.</p>
  
  <pre><code>SELECT 
      [Extent1].[ID] AS [ID], 
      [Extent1].[StatusID] AS [StatusID], 
      [Extent1].[KlantID] AS [KlantID], 
      [Extent1].[SoortID] AS [SoortID], 
      [Extent1].[isVerwijderd] AS [isVerwijderd], 
      [Extent1].[Aantalkarren] AS [Aantalkarren], 
      [Extent2].[ID] AS [ID1], 
      [Extent2].[OpdrachtID] AS [OpdrachtID], 
      [Extent2].[Vertrekdatum] AS [Vertrekdatum], 
      [Extent2].[Vertrektijd] AS [Vertrektijd], 
      [Extent3].[ID] AS [ID2], 
      [Extent3].[OpdrachtID] AS [OpdrachtID1], 
      [Extent3].[KarID] AS [KarID], 
      [Extent3].[Gesealed] AS [Gesealed], 
      [Extent3].[Aantal] AS [Aantal], 
      [Extent3].[SamenvoegOpdrachtkarID] AS [SamenvoegOpdrachtkarID], 
      [Extent3].[AanmaakDatum] AS [AanmaakDatum]
      FROM   [dbo].[Opdracht] AS [Extent1]
      INNER JOIN [dbo].[OpdrachtLogistiek] AS [Extent2] ON [Extent1].[ID] = [Extent2].[OpdrachtID]
      INNER JOIN [dbo].[OpdrachtKar] AS [Extent3] ON [Extent1].[ID] = [Extent3].[OpdrachtID]
      WHERE (40826 = [Extent2].[Vertrekdatum]) AND ( NOT ((0 = [Extent3].[Gesealed]) AND ([Extent3].[Gesealed] IS NOT NULL)))
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>The code is okay. The data I wanted to display did not exist. I made a well known typing mistake. I filled in "40826" instead of "40822". Thanks for all the help.</p>
  
  <p><strong>Update 3:</strong> 
  For people wondering how my model looks like:</p>
  
  <pre><code>public class Order_OrderCart_OrderLogisticsModel
  {
      private Order order;
  
      public Order Order
      {
          get { return order; }
          set { order = value; }
      }
  
      private OrderLogistics logistics;
  
      public OrderLogistics Logistics
      {
          get { return logistics; }
          set { logistics = value; }
      }
  
      private OrderCart cart;
  
      public OrderCart Cart
      {
          get { return cart; }
          set { cart = value; }
      }
  }
  </code></pre>