Hi,
I already asked the question on SO (http://stackoverflow.com/questions/
6919771/select-minimum-of-a-subquery-in-nhibernate) but did not get a
satisfying answer so I thought I might try here as well. To recap the
question:
I have a table of packs which each have a start time. Of the last X
started packs I want the earliest start time. I can achieve that by
using the following SQL query:
SELECT MIN(TopTimes.StartTime)
FROM (SELECT TOP X StartTime FROM Pack ORDER BY StartTime DESC) AS
TopTimes
(and of course substituting X for an actual number). However I would
like to use a more NHibernate way of doing this but I could not figure
out how to express this query with the criteria API or HQL. I got as
far as this:
DetachedCriteria.For<Pack>()
.SetProjection(Projections.Property("StartTime"))
.SetMaxResults(X)
.AddOrder(Order.Desc("StartTime"));
which gives me the subquery but then how do I get the minimum
projection on this? Can't be that hard but somehow it eludes me me.
Any input appreciated.
Cheers
Christian
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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.