You are currently browsing legacy 3.5 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Including documents

You may have read about includes earlier, if not, note that 'includes' option gives you the ability to side-load additional documents in a single server call. Transformers also contain this powerful feature and you can take advantage of it by using Include method.

public class Products_NameCategoryAndSupplier : AbstractTransformerCreationTask<Product>
	public class Result
		public string Name { get; set; }

		public string Category { get; set; }

		public string Supplier { get; set; }

	public Products_NameCategoryAndSupplier()
		TransformResults =
			products =>
			from product in products
			let supplier = Include<Supplier>(product.Supplier)
			let category = Include<Category>(product.Category)
			select new
				Name = product.Name,
				Category = product.Category,
				Supplier = product.Supplier

Products_NameCategoryAndSupplier.Result result = session
	.Where(x => x.Name == "Chocolade")
	.TransformWith<Products_NameCategoryAndSupplier, Products_NameCategoryAndSupplier.Result>()

int numberOfRequests = session.Advanced.NumberOfRequests;

Category category = session.Load<Category>(result.Category); // no server call
Supplier supplier = session.Load<Supplier>(result.Supplier); // no server call

Assert.Equal(numberOfRequests, session.Advanced.NumberOfRequests);