Chapter 15. HQL: The Hibernate Query Language: 15.1. Case Sensitivity

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Chapter 15.

HQL: The Hibernate Query Language


NHibernate is equipped with an extremely powerful query language that (quite intentionally) looks very much
like SQL. But don't be fooled by the syntax; HQL is fully object-oriented, understanding notions like inherit-
ance, polymorphism and association.

15.1. Case Sensitivity


Queries are case-insensitive, except for names of .NET classes and properties. So is the same as
is the same as but is not and is not .

This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable,
but we find this convention ugly when embedded in C# code.

15.2. The from clause


The simplest possible NHibernate query is of the form:

which simply returns all instances of the class .

Most of the time, you will need to assign an alias, since you will want to refer to the in other parts of the
query.

This query assigns the alias to instances, so we could use that alias later in the query. The keyword
is optional; we could also write:

Multiple classes may appear, resulting in a cartesian product or "cross" join.

It is considered good practice to name query aliases using an initial lowercase, consistent with naming stand-
ards for local variables (eg. ).

15.3. Associations and joins


We may also assign aliases to associated entities, or even to elements of a collection of values, using a .

NHibernate 5.2 145

You might also like