see on GitHub

Session: Querying: How to perform projection?

There are a couple types of projections:

Select

The most common projection is done by using select method.

Example I

// request 'FirstName' and 'LastName' from server
// and project it to 'EmployeeFirstAndLastName'
session
  .query(Employee.class)
  .select(EmployeeFirstAndLastName.class, "firstName", "lastName")
  .toList();

Example II

// request 'FirstName' and 'LastName' from server
// and project it to 'EmployeeFirstAndLastName'
QHowToPerformProjection_EmployeeFirstAndLastName e =
  QHowToPerformProjection_EmployeeFirstAndLastName.employeeFirstAndLastName;
session
  .query(Employee.class)
  .select(EmployeeFirstAndLastName.class, e.firstName, e.lastName)
  .toList();

TransformWith

Detailed article about using transformers with queries can be found here.

Remarks

Note

Projections request from server an array of fields to download, if index contains those fields (stores them) they will come directly from index, if not values from document will be used. You can read more about storing fields here.

Raven/ImplicitFetchFieldsFromDocumentMode setting can be altered to change the behavior of field fetching. By default it allows fetching fields from document if index is missing them (they are not stored), but this can be changed to skipping those fields or even throwing an exception. Read more about this configuration option here.

Note

Projected entities (even named types) are not being tracked by session.