0

我有一個表頭和明細之間有許多如在下面的類NHibernate的組由parentId的,並從父表中的值這個parentId的

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表中獲取相應的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[]>(); 

回答

0
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[]>();