Session: Querying: How to perform projection?
There are a couple types of projections:
- using Select
- using transformer TransformWith
The most common projection is done by using
// request 'FirstName' and 'LastName' from server // and project it to 'EmployeeFirstAndLastName' session .query(Employee.class) .select(EmployeeFirstAndLastName.class, "firstName", "lastName") .toList();
// 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();
Detailed article about using transformers with queries can be found here.
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.
Projected entities (even named types) are not being tracked by session.