Session: How to perform operations lazily?

Operation execution for operations such as load, load with includes, loadStartingWith, moreLikeThis and queries can be deferred till needed using lazy session operations. Those operations ca be accessed using lazily in advanced() session operations.


Available operations are:

  • load - described here.
  • load with Includes - described here.
  • loadStartingWith - described here.
  • moreLikeThis - described here.


Dedicated article about lazy queries can be found here.


net.ravendb.abstractions.basic.Lazy<Employee> employeeLazy =
  session.advanced().lazily().load(Employee.class, "employees/1");
Employee employee = employeeLazy.getValue(); // load operation will be executed here

Executing all pending lazy operations

To execute all pending lazy operations use executeAllPendingLazyOperations method from eager session operations found under eagerly in advanced() session operations.

net.ravendb.abstractions.basic.Lazy<List<Employee>> emplyeesLazy =
session.advanced().eagerly().executeAllPendingLazyOperations(); // query will be executed here

List<Employee> employees = emplyeesLazy.getValue();