NHibernate 按 parentId in child 分组并从 parent table 中获取此 parentId 的值

NHibernate group by parentId in child and get the value from parent table for this parentId

我在 Header 和 Detail 之间有一对多,如下所示 class

public class Header
{
    public virtual string ScriptNumber { get; set; }
    public virtual IList<Detail> Details { get; set; }
    public virtual string StartTime { get; set; }
}

public class Detail
{
    public virtual string ScriptNumber { get; set; }
    public virtual DateTime UpdatedDate { get; set; }
    public virtual Header ProgramHeader { get; set; }   
}

我正在尝试查询要按 ScriptNumber 分组的详细信息,并从 Header table 中获取相应的 StartTime。任何人都可以帮助我如何做到这一点。 目前我的 NHibernate 查询是:

var changesInDetail = _session.QueryOver<Detail>()
                        .Where(x => x.UpdatedDate.IsBetween(changedFrom).And(changedTo))
                        .SelectList(list => list.SelectGroup(pr => pr.ScriptNumber))
                        .Future<string>();

How to get the StartTime from Header for the grouped by value in Detail?

以下工作如我所料。任何人都可以确认这是否是最好的方法吗?

        var changedScriptsInDetail1 = _session.QueryOver<Detail>(() => detailAlias)
                .JoinQueryOver(d => d.ProgramHeader, () => headerAlias)
                .Where(() => detailAlias.UpdatedDate.IsBetween(changedFrom).And(changedTo))
                .SelectList(list => list
                    .SelectGroup(pr => pr.ScriptNumber)
                    .SelectGroup(()=>headerAlias.StartTime)
                 )
                 .List<object[]>();
    var changedScriptsInDetail1 = _session.QueryOver<Detail>(() => detailAlias)
            .JoinQueryOver(d => d.ProgramHeader, () => headerAlias)
            .Where(() => detailAlias.UpdatedDate.IsBetween(changedFrom).And(changedTo))
            .SelectList(list => list
                .SelectGroup(pr => pr.ScriptNumber)
                .SelectGroup(()=>headerAlias.StartTime)
             )
             .List<object[]>();