title: Transforming Results
body: <p>My colleagues have asked me if given the <a href="http://ravendb.net/docs/theory/document-structure-design">orderline</a> example, it'd be possible to initialize a viewmodel looking like this:</p>
  
  <pre><code>OrderViewModel
     string OrderId
     string CustomerName
     List&lt;OrderLineViewModel&gt; OrderLines
  
  OrderLineViewModel
     string ProductName
     string ROI
     int Quantity
  </code></pre>
  
  <p>From an index? </p>
  
  <p>I've tried doing a transform that successfully loads the customer name but could never manage to get the associated product information from the orderline. Can this be done with a transform or would I need to project from index fields?</p>
  
  <p>Cheers,</p>
  
  <p>James</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>We're trying to populate view models directly from a query.
  We tried the following index:</p>
  
  <pre><code>public class OrdersViewIndex : AbstractIndexCreationTask&lt;Order&gt;
  {
     Map = orders =&gt; from order in orders
                     select new {
                                  OrderId = order.id
                                };
  
     Transform = (database, orders) =&gt; from order in orders
                                       let customer = database.Load&lt;Customer&gt;(order.customerId)
                                       select new {
                                                    OrderId = order.id,
                                                    CustomerName = customer.Name,
                                                    OrderLines = // This is where I struggled to answer my colleagues questions as i'd need to load product name.
                                                  }
  }
  </code></pre>