title: Mapping one to many with Dapper
body: <p>Trying to figure this out, but I can't get it to work. This query:</p>
  
  <pre><code>select MultiCollections.*, Collections.* from MultiCollections 
  left join MultiCollectionCollections on MultiCollections.Id = MultiCollectionCollections.MultiCollectionId
  left join  Collections on MultiCollectionCollections.CollectionId = Collections.Id
  where MultiCollections.UserId=5
  </code></pre>
  
  <p>This will return this data:</p>
  
  <p><a href="https://i.stack.imgur.com/g3nVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g3nVm.png" alt="enter image description here"></a>
  As you can see, row 1 and 2 are from the same Title. The data behind them are books.
  Row 3 and 4 are also collections but don't have books.</p>
  
  <p>I have two objects in my code:
  MultiCollection
  Collection</p>
  
  <p>Both correspond with the data given in the result of the query:
  Id, UserId and Title are for object MultiCollection. Other data are for the object Collection.</p>
  
  <p>I expect to see three MultiCollections in my C# code:
  Action
  Drama
  Fiction</p>
  
  <p>Action will have 2 collections. Drama and Fiction should be empty.</p>
  
  <p>Instead, I get 4 MultiCollections and none of them contains Collections. My C# code:</p>
  
  <pre><code>public IEnumerable&lt;MultiCollection&gt; GetAll(int userId)
      {
          string query = @"select MC.*, C.* from MultiCollections  MC
                          left join MultiCollectionCollections MCC on MC.Id = MCC.MultiCollectionId
                          left join  Collections C on MCC.CollectionId = C.Id
                          where UserId=" + userId;
  
          using (DbConnection connection = ConnectionFactory())
          {
              connection.Open();
              return connection.Query&lt;MultiCollection, List&lt;Collection&gt;, MultiCollection&gt;(query,
                  (a, s) =&gt;
                  {
                      a.Collections = s;
                      return a;
                  });
          }
      }
  </code></pre>
  
  <p>When running the code I would expect this:</p>
  
  <pre><code>Action    
      Collections    
         -&gt; Book 1    
         -&gt; Book 2     
  Drama    
     Collections    
         Null     
  Fiction    
      Collections    
          Null
  </code></pre>
  
  <p>I have no idea what I'm doing wrong.</p>