Session: How to Perform Operations Lazily
Operation execution for operations such as load
, load with includes
, loadStartingWith
and queries can be deferred till needed using lazy session operations. Those operations ca be accessed using lazily
property found in advanced
session operations.
Operations
Available operations are:
Querying
Dedicated article about lazy queries can be found here.
Example
net.ravendb.client.documents.Lazy<Employee> employeeLazy = session
.advanced()
.lazily()
.load(Employee.class, "employees/1-A");
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
property in advanced
session operations.
net.ravendb.client.documents.Lazy<List<Employee>> employeesLazy = session
.query(Employee.class)
.lazily();
session.advanced().eagerly().executeAllPendingLazyOperations(); // query will be executed here
List<Employee> employees = employeesLazy.getValue();