我在Header和Detail之间有一对多,如下面的类
所示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查询Detail以分组,并从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 :(得分: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[]>();