6

我有一个 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).

4

1 回答 1

0

尝试使用此语句,我使用了 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();

我希望它会有所帮助。

于 2011-04-01T09:54:20.773 回答