title: RavenDb: Join data with index
body: <p>In my database I have a list of cases:</p>
  
  <pre><code>{ Id: 1, Owner: "guid1", Text: "Question1" }
  { Id: 2, Owner: "guid1", Text: "Question2" }
  { Id: 3, Owner: "guid2", Text: "Question3" }
  </code></pre>
  
  <p>When querying for data I would also like to have (in my index, result) number of cases each Owner has. So I created a map/reduce index on this collection:</p>
  
  <pre><code>public class RelatedCases
  {
      public Guid Owner { get; set; }
      public int Count { get; set; }
  }
  
  public class RelatedCaseIndex : AbstractMultiMapIndexCreationTask&lt;RelatedCases&gt;
  {
      public RelatedCaseIndex()
      {
          AddMap&lt;CaseDocument&gt; (c =&gt; c.Select(a =&gt; new { a.Owner, Count = 1 }));
  
          Reduce = result =&gt; result
              .GroupBy(a =&gt; a.Owner)
              .Select(a =&gt; new 
              { 
                  Owner = a.Key, 
                  Count = a.Sum(b =&gt; b.Count)
              });
      }
  }
  </code></pre>
  
  <p>Now I just have no idea how to produce a query to include the data from the index. Based on documentation I tried something like:</p>
  
  <pre><code>session.Query&lt;CaseDocument&gt;().Customize(a =&gt; a.Include ...)
  </code></pre>
  
  <p>or TransformResults on a CaseIndex, which didn't work out properly.</p>
  
  <p>I know I could just requery raven to get me list of all RelatedCases in a separate query, but I would like to do it in one round-trip.</p>