see on GitHub

Session : Querying : How to stream query results?

Query results can be streamed using Stream method from Advanced session operations.

Syntax

IEnumerator<StreamResult<T>> Stream<T>(IQueryable<T> query);

IEnumerator<StreamResult<T>> Stream<T>(
	IQueryable<T> query,
	out QueryHeaderInformation queryHeaderInformation);

IEnumerator<StreamResult<T>> Stream<T>(IDocumentQuery<T> query);

IEnumerator<StreamResult<T>> Stream<T>(
	IDocumentQuery<T> query,
	out QueryHeaderInformation queryHeaderInformation);

Parameters
query IQueryable or IDocumentQuery Query to stream results for.
queryHeaderInformation QueryHeaderInformation Information about performed query.
Return Value
IEnumerator<StreamResult> Enumerator with entities.
QueryHeaderInformation Information about performed query.

Example I

IQueryable<Employee> query = session
	.Query<Employee, Employees_ByFirstName>()
	.Where(x => x.FirstName == "Robert");

IEnumerator<StreamResult<Employee>> results = session.Advanced.Stream(query);

while (results.MoveNext())
{
	StreamResult<Employee> employee = results.Current;
}

Example II

IDocumentQuery<Employee> query = session
	.Advanced
	.DocumentQuery<Employee, Employees_ByFirstName>()
	.WhereEquals(x => x.FirstName, "Robert");

QueryHeaderInformation queryHeaderInformation;
IEnumerator<StreamResult<Employee>> results = session.Advanced.Stream(query, out queryHeaderInformation);

while (results.MoveNext())
{
	StreamResult<Employee> employee = results.Current;
}

Remarks

Streaming results only works for queries that were made against a (predefined) static index.