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.
Complete the steps in the Getting Started section at the beginning of this chapter.
Add a new
class
namedRecipe
to the folder:using System; using NH4CookbookHelpers; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Transform; namespace QueryRecipes.ResultTransformers { public class Recipe : QueryRecipe { protected...