Hibernate version:
1.2
I am searching for a way of how to select specific properties using ICriteria, and not all objects.
As an example, the expected end result is array of object[] , containing the required properties.
The code i expect might look like this:
Code:
IQuery sqlQuery = sess.CreateSQLQuery("select cat.Name, cat.Surname, .... from cats cat");
sqlQuery.AddCritieria(Expression.Eq("Name", "kitty"))
sqlQuery.AddOrder(Order.Asc(Name"))
sqlQuery.SetMaxResults(50);
IList cats = sqlQuery.List();
What i actually found in NHibernate 1.2 is
* a SQL based query (
http://www.hibernate.org/hib_docs/nhibe ... rysql.html).
Code:
sess.CreateSQLQuery("select {cat.*} from cats {cat}", "cat", typeof(Cat));
However, this sql query returns me a collection of cats, and not the properties i need.
* There are many more query types detailed in
nhibernate chapter 9
but i could not find what i need, i.e. ICriteria fetching with ability to select distinct properties.
Is there a way to achieve this?
To summarize, what I want is ability to construct queries using ICriteria API, and to bypass hydration - instead of real objects i want to get a raw sql result table
Update
I found that projections might help. Reading them..
12.7. Projections, aggregation and grouping