title: Dapper multi object query One-Many
body: <p>Not really sure why I'm not getting the child object populated.</p>
  <p>My tables:</p>
  <pre><code>Product:
         [ProductId]
        ,[Brand]
        ,[Model]
  
  StoreProduct:
         [StoreId]
        ,[ProductId]
        ,[StoreProductId]
  </code></pre>
  <p>Class</p>
  <pre><code>public class Product
  {
          public Guid ProductId { get; set; }
          public string Brand { get; set; }
          public string Model { get; set; }
          public virtual List&lt;StoreProduct&gt; StoreProducts { get; set; }
  }
  
  public class StoreProduct
  {
          public int StoreId { get; set; }       //Key 0
          public Guid ProductId { get; set; }    //Key 1
          public Store Store { get; set; }
          public Product Product { get; set; }
          public string StoreProductId { get; set; } //A new Id specific for each store
  }
  </code></pre>
  <p>My Dapper Code</p>
  <pre><code>string sql = &quot;SELECT * FROM StoreProduct AS A INNER JOIN Product AS B ON A.ProductId = B.ProductId WHERE A.StoreProductId = @StoreProductId and A.StoreId = @StoreId&quot;;
                      var connection = AppDbContext.Database.GetDbConnection();
                      return connection.Query&lt;StoreProduct, Product, Product&gt;(
                          sql, 
                          (StoreProduct, Product) =&gt; { StoreProduct.ProductId = Product.ProductId; return Product; }, 
                          new { StoreProductId = storeProductId, StoreId = StoreID }, splitOn: &quot;ProductId&quot;)
                      .FirstOrDefault();
  </code></pre>
  <p>What the DB returns:</p>
  <p><img src="https://i.stack.imgur.com/lyUzG.png" alt="enter image description here" /></p>
  <p>But... <code>StoreProducts</code> List is null.</p>