按照子集的最大值订购父母

时间:2016-02-03 10:19:20

标签: c# oracle nhibernate

我正在尝试将下面的查询翻译为nhibernate查询代码。 但是,我没有看到让这件事发挥作用的任何方向

SELECT *
    FROM    parentTable parent
         INNER JOIN
            (  SELECT MAX (child.dateCreated) AS dateFirstCreated, child.parentId
                 FROM childTable child
             GROUP BY child.parentId) c
         ON c.parentId = parent.id
ORDER BY c.dateFirstCreated DESC;

我唯一拥有的但是还不够(完全没有表现力)是:

public void DoSomething()
{
       var query = Session.QueryOver<ParentTable>();
       var detachedCriteria = DetachedCriteria.For<ChildTable>()
          .SetProjection(Projections.Max<ChildTable>(x => x.DateCreated));
       var orderBuilder = query.OrderBy(Projections.SubQuery(detachedCriteria));
       orderBuilder.Asc();
       var result = query.List().ToList();
}

0 个答案:

没有答案