If I have a query where I'm creating a sql-projected select, and alias it, 
what's the proper way to add ordering of this aliased projection? 
The QueryOver api only has an "OrderByAlias" that takes a function from 
which it extracts a member, hence I can't use it.
Right now I'm resorting to the following which works but looks kind of 
hacky to me (the projection2 part)

var projection = Projections.SqlProjection("COUNT({alias}.ReportId) 
OVER(PARTITION BY {alias}.ReportId) AS messageCount", new[] { 
"messageCount" }, new IType[] { NHibernate.NHibernateUtil.Int32});
var projection2 = Projections.SqlProjection("messageCount as messageCount", 
new[] { "messageCount" }, new IType[] { NHibernate.NHibernateUtil.Int32});

var resuls = Session.QueryOver<Report>()
                    .Fetch(r => r.Messages).Eager
                    .SelectList(list => list
                        .Select(Projections.Distinct(Projections.Id()))
                        .Select(projection)
                    ).OrderBy(projection2).Desc.Take(100).List<object>();

Never mind the actual query, that could be done in other ways, I'm only 
interested in how the "OrderBy" ought to be.

I also tried falling back to ICriteria, replacing the OrderBy like so:
...UnderlyingCriteria.AddOrder(Order.Desc("messageCount")).SetMaxResults(100).List<object>();

But this fails on the account that "messageCount" is expected to be a 
property of the Report entity.

And a follow up question. NHibernate still only supports the "{alias}" to 
refer to the root entity in a projection? No way to reference any joined 
aliases?

Cheers!

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/4Xtb11j4L5kJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to