see on GitHub

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.


Available operations are:

  • Load - described here.
  • Load with Includes - described here.
  • LoadStartingWith - described here.


Dedicated article about lazy queries can be found here.


Lazy<Employee> employeeLazy = session

Employee employee = employeeLazy.Value; // 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.

Lazy<IEnumerable<Employee>> employeesLazy = session

session.Advanced.Eagerly.ExecuteAllPendingLazyOperations(); // query will be executed here

IEnumerable<Employee> employees = employeesLazy.Value;