我有一个HQL查询:
select max(l.Num) from SomeTable l group by l.Type, l.Iteration
如何将其转换/转换为QueryOver?
接下来的一个:
var grouped = session.QueryOver<SomeTable>()
.SelectList(l => l
.SelectGroup(x => x.Type)
.SelectGroup(x => x.Iteration)
.SelectMax(x => x.Num));
将生成SQL:
SELECT
MAX(l.Num),
l.Type,
l.Iteration
FROM
SomeTable l
GROUP BY
l.Type,
l.Iteration
这不是我期望的-我不想在Select中使用Type和Iteration。
我正在使用该查询作为
select z from c where z IN (subquery)
的子查询。 最佳答案
尝试使用此语句,我已经使用了Aliases和UnderlyingCriteria
SomeTable someTb = null;
var grouped = session.QueryOver<SomeTable>(() => someTb)
.SelectList(l => l.SelectMax(() => someTb.lnum))
.UnderlyingCriteria.SetProjection(
Projections.Group(() => someTb.Type)
,Projections.Group(() => someTb.Iteration))
.List();
希望对您有所帮助。