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 property found 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.


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;