title: ravendb index, query on child collection
body: <p>I want to get a summary of all products, as only the latest OrderHistory is of interest where I want to use this. I have thousands of products with hundreds of OrderHistory each, but now I only want the product id and the latest OrderHistory for each product.</p>
  
  <pre><code>public class ProductSummary
  {
      public int ProductId { get; set; }
      public OrderHistory LastOrderHistory { get; set; }
  }
  </code></pre>
  
  <p>The OrderHistory is stored inside the Product document like this:</p>
  
  <pre><code>public class Product
  {
      public int Id { get; set; }
      public int MarketGroupId { get; set; }
      public string Name { get; set; }
      public decimal Price { get; set; }
      public List&lt;OrderHistory&gt; OrderHistory { get; set; }
  }
  </code></pre>
  
  <p>And this is what OrderHistory looks like:</p>
  
  <pre><code>public class OrderHistory
      {
          public long OrderCount { get; set; }
          public long Volume { get; set; }
          public DateTime date { get; set; }
          public double AvgPrice { get; set; }
      }
  </code></pre>
  
  <p>Now I've tried a few approaches on the index and query to get this running, this is my latest try, but it returns no results.</p>
  
  <pre><code>public class LatestProductOrderHistory : AbstractIndexCreationTask&lt;Product, ProductSummary&gt;
  {
      public LatestProductOrderHistory()
      {
          Map = products =&gt; from p in products
                            from oh in p.OrderHistory
              select new
              {
                  ProductId = p.Id,
                  LastOrderHIstory = p.OrderHistory.OrderByDescending(o =&gt; o.date).Last()
              };
  
          StoreAllFields(FieldStorage.Yes);
      }
  }
  </code></pre>
  
  <p>And finally my query:</p>
  
  <pre><code>                var results = session
                      .Query&lt;ProductSummary, LatestProductOrderHistory&gt;()
                      .ProjectFromIndexFieldsInto&lt;ProductSummary&gt;()
                      .Take(1024)
                      .Skip(start)
                      .ToList();
  </code></pre>
  
  <p>This combination gives me no results, I have never made indexes in ravendb before, so I'm sorry if this is a dumb question.</p>
  
  <p><strong>EDIT:</strong> Well, I'm not sure what I changed, but now I'm getting "Could not read value for property: Id"
  <strong>EDIT2:</strong> The strange issue in previous edit was solved by restarting vs and ravendb, so current result is no result</p>