when using Nhiberante Criteria API or HQL with grouping, query returns list of arrays of entity properties List<Object[]>
at which grouping was made. If I need to return only certain property how can I do that? preferably with Nhiberane API if possible
views:
32answers:
2
A:
With HQL, you just SELECT
the properties you want:
var query = Session.CreateQuery("select p.Id, p.Price from Products p where p.Status = 'A'")
.List().Cast<object[]>();
It's similar with NHibernate.Linq:
var query = from p in Session.Linq<Product>()
where p.Status == "A"
select new
{
p.Id, p.Price
};
Rafael Belliard
2010-09-14 12:15:04
I can't quite understand example with hql. What for Cast<object[]> is? When using grouping (unlike your example) data by default returned as List<object[]> (in your example it would hold Integer and Decimal). If I need only Prices of Products, how can I get them?
kilonet
2010-09-14 21:13:23