title: Dapper map multiple joins Sql Query
body: <p>I want to map complex object to dapper result from query which has two inner joins. I know we've solution to map one inner join but I want to map two inner joins result.</p>
  
  <p>Here is the Scenario:</p>
  
  <p>My Classes are:</p>
  
  <pre><code>public class Order 
  {
      public int id { get; set; }
      public string order_reference { get; set; }
      public string order_status { get; set; }
      public List&lt;OrderLine&gt; OrderLines { get; set; }
  }
  
  public class OrderLine
  {
      public int id { get; set; }
      public int order_id { get; set; }
      public string product_number { get; set; }
      public List&lt;OrderLineSize&gt; OrderLineSizes { get; set; }
  }
  
  public class OrderLineSize
  {
      public int id { get; set; }
      public int order_line_id { get; set; }
      public string size_name { get; set; }
  }
  </code></pre>
  
  <blockquote>
    <p>Order has OrderLines as List and OrderLine as OrderLineSizes as List.</p>
  </blockquote>
  
  <p>Now, Here is my query base on that I want to populate <code>List&lt;Order&gt;</code> with correct data:</p>
  
  <pre><code>SELECT *
  FROM orders_mstr o
  INNER JOIN order_lines ol ON o.id = ol.order_id
  INNER JOIN order_line_size_relations ols ON ol.id = ols.order_line_id
  </code></pre>
  
  <p>Here is what I tried so far:</p>
  
  <pre><code>var lookup = new Dictionary&lt;int, Order&gt;();
              connection.Query&lt;Order, OrderLine, Order&gt;(@"
                      SELECT o.*, ol.*
                      FROM orders_mstr o
                      INNER JOIN order_lines ol ON o.id = ol.order_id                    
                      ", (o, ol) =&gt; {
                      Order orderDetail;
                      if (!lookup.TryGetValue(o.id, out orderDetail))
                      {
                          lookup.Add(o.id, orderDetail = o);
                      }
                      if (orderDetail.OrderLines == null)
                          orderDetail.OrderLines = new List&lt;OrderLine&gt;();
                      orderDetail.OrderLines.Add(ol);
                      return orderDetail;
                  }).AsQueryable();
  
              var resultList = lookup.Values;
  </code></pre>
  
  <p>Using this, I can successfully map order object with OrderLine but I want to populate OrderLineSizes as well with correct data.</p>