1

Let's take simple index from RavenDb documentation as an example:

public class SampleIndex : AbstractIndexCreationTask<Invoice>
{
    public SampleIndex()
    {
        Map = invoices => from invoice in invoices
                          select new
                          {
                              CustomerId = invoice.CustomerId,
                              CustomerName = LoadDocument<Customer>(invoice.CustomerId).Name
                          };
    }
}

Let's assume I need to have multiple customer properties in the index or transformer. Should I call LoadDocument<Customer>(invoice.CustomerId).SomeProperty every time (may be RavenDb optimizes it and actually load document once) or is there any special syntax (similar to let in LINQ)?

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

2 Answers2

1

LoadDocument is cached, so calling it once or multiple times for the same document doesn't really matter.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
0

You can use .Include<Customer>(invoice => invoice.CustomerId) with your query, so all referenced customers are returned with the result. See Load with Includes.

Thomas Freudenberg
  • 5,048
  • 1
  • 35
  • 44
  • Although this is possible with conventional querying, he's asking this question regarding an index which doesn't support `Include()` as far as I'm aware. – CthenB Jun 17 '16 at 00:17