Using the Hibernate Query Language

So far, we've covered various queries using LINQ, the Criteria API and its sibling, the QueryOver syntax. NHibernate provides another, more powerful, query method named Hibernate Query Language, which is a domain-specific language that blends familiar SQL-like syntax with Object-Oriented thinking. In this recipe, we'll show you how to use the Hibernate Query Language to perform the same queries as in the previous recipes.

Getting ready

Complete the Getting Ready section at the beginning of this chapter.

How to do it…

  1. Add a new folder named QueryByHql to the project.
  2. Add a new class named HqlQueries to the folder:
    using System.Collections.Generic; using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; ...

Get NHibernate 4.x Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.