Take the 2-minute tour ×

I have a project where I'm using NHibernate to handle bindings to the database. So far I have mostly been using the basics when it comes to queries. Now I'm struggling with a more difficult query, and I notice new parts of NHibernate. In particular I'm curious about SetProjection, which seems to be important when doing queries.

What is a Projection, and how will I typically use it? I am assuming that a projection is a general term when it comes to databases, so you are welcome to give more general answers too..

share|improve this question
add comment

2 Answers

up vote 19 down vote accepted

Projection as Antoine said is transformation. In terms of query it is:


*PROJECTION* is expression for data transformation.



The Criteria equivalent would be:

List orders = session.createCriteria(Order.class).list();

No projection here, we take data without transformation. If we want one:


Here, the Projection class comes into play. The above query can be rewritten into a Criteria query as:

List products=session.createCriteria(Product.class)

So we project all rows to single item: name field.

There are other projections: Projection.rowCount() for example (for COUNT(*))

share|improve this answer
would be glad to hear reason behind downvote –  Andrey Jan 20 '11 at 12:47
Thanks! Clarifying. And yes - I started by googling, but I didn't really find the answer. Btw; downvote wasn't from me. +1 –  stiank81 Jan 20 '11 at 15:55
As for first row of your answer, I got here from first result of google =) –  Johnny_D Apr 23 '12 at 14:42
add comment

I don't know about NHibernate, but in general, a projection is a transformation of a set into another set. In SQL, it is expressed as a SELECT.

share|improve this answer
add comment

Your Answer


