Using result transformers
In normal query scenarios we can rely on NHibernate's mechanisms to convert the query results into entities and objects that we can use. Sometimes, however, the queries may not map to classes we have defined in the mappings or maybe we want to customize what is returned. NHibernate provides many extension points and one of those is a result transformer, which can be injected into the flow of a query. It transforms the results of a query into the results that we need.
In the following recipe, we will try out two of the most commonly used built-in transformers.
How to do it…
- Complete the steps in the Getting Started section at the beginning of this chapter.
- Add a new folder named
ResultTransformers
to the project. - Add a new ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.