开发者

NHibernate: returning List<EntityType> not List<Object[]> when using grouping

when using Nhiberante Criteria API or HQL with grouping, query returns list of arrays of entity properties 开发者_Python百科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


Have you tried using the Transformers class?

See section 16.1.5


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
            };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜