Using QueryOver projections and aggregates
In some cases, we only need specific properties of an entity. In other cases, we may need the results of an aggregate function, such as average or count. In this recipe, we'll show you how to write QueryOver
queries with projections and aggregates.
Getting ready
Complete the Getting Ready instructions at the beginning of this chapter.
How to do it…
Add a new folder named
QueryOverProjections
to the project.Add a new class named
QueryOverAggregateQueries
to the folder, having the following code:using System; using System.Collections.Generic; using System.Linq; using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Criterion; namespace QueryRecipes.QueryOverProjections { public class QueryOverAggregateQueries : IAggregateQueries { private readonly ISession _session; public QueryOverAggregateQueries(ISession session) { _session = session; } } }
Add the following method...