title: How do I write one to many query in Dapper.Net?
body: <p>I've written this code to project one to many relation but it's not working:</p>
  
  <pre><code>using (var connection = new SqlConnection(connectionString))
  {
     connection.Open();
  
     IEnumerable&lt;Store&gt; stores = connection.Query&lt;Store, IEnumerable&lt;Employee&gt;, Store&gt;
                          (@"Select Stores.Id as StoreId, Stores.Name, 
                                    Employees.Id as EmployeeId, Employees.FirstName,
                                    Employees.LastName, Employees.StoreId 
                             from Store Stores 
                             INNER JOIN Employee Employees ON Stores.Id = Employees.StoreId",
                          (a, s) =&gt; { a.Employees = s; return a; }, 
                          splitOn: "EmployeeId");
  
     foreach (var store in stores)
     {
         Console.WriteLine(store.Name);
     }
  }
  </code></pre>
  
  <p>Can anybody spot the mistake?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>These are my entities:</p>
  
  <pre><code>public class Product
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public double Price { get; set; }
      public IList&lt;Store&gt; Stores { get; set; }
  
      public Product()
      {
          Stores = new List&lt;Store&gt;();
      }
  }
  
  public class Store
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public IEnumerable&lt;Product&gt; Products { get; set; }
      public IEnumerable&lt;Employee&gt; Employees { get; set; }
  
      public Store()
      {
          Products = new List&lt;Product&gt;();
          Employees = new List&lt;Employee&gt;();
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I change the query to:</p>
  
  <pre><code>IEnumerable&lt;Store&gt; stores = connection.Query&lt;Store, List&lt;Employee&gt;, Store&gt;
          (@"Select Stores.Id as StoreId ,Stores.Name,Employees.Id as EmployeeId,
             Employees.FirstName,Employees.LastName,Employees.StoreId 
             from Store Stores INNER JOIN Employee Employees 
             ON Stores.Id = Employees.StoreId",
           (a, s) =&gt; { a.Employees = s; return a; }, splitOn: "EmployeeId");
  </code></pre>
  
  <p>and I get rid of exceptions! However, Employees are not mapped at all. I am still not sure what problem it had with <code>IEnumerable&lt;Employee&gt;</code> in first query.</p>