我如何获得列表以及子列表,其中子列表在 NHibernate 中具有某些条件
How can i get List along with child list where child list having some condition in NHibernate
我在 NHibernate 中编写了如下查询:
var queryResult = CurrentSession.QueryOver()
.Where(r => r.StatusId == 1)
.JoinQueryOver(a => a.ActorList)
.Where(s=>s.IsActor==1)
.List()
.Distinct()
.ToList();
我正在尝试仅检索 Where(s=>s.IsActor==1)
,但它正在获取记录
Where(s=>s.IsActor==0)
还有...
如何才能只获得IsActor==1
条记录?
提前致谢
您需要在连接中指定一个谓词,以便它应用于连接而不是顶部 where:
(看起来像 ...LEFT JOIN actor on actor.Id = p.ActorId AND IsActor = 1
)
Actor actorAlias = null;
var queryResult = CurrentSession.QueryOver()
.Where(r => r.StatusId == 1)
.Left.JoinQueryOver(r => r.ActorList, () => actorAlias, a => a.IsActor==1)
.List()
.Distinct()
.ToList();
我在 NHibernate 中编写了如下查询:
var queryResult = CurrentSession.QueryOver()
.Where(r => r.StatusId == 1)
.JoinQueryOver(a => a.ActorList)
.Where(s=>s.IsActor==1)
.List()
.Distinct()
.ToList();
我正在尝试仅检索 Where(s=>s.IsActor==1)
,但它正在获取记录
Where(s=>s.IsActor==0)
还有...
如何才能只获得IsActor==1
条记录?
提前致谢
您需要在连接中指定一个谓词,以便它应用于连接而不是顶部 where:
(看起来像 ...LEFT JOIN actor on actor.Id = p.ActorId AND IsActor = 1
)
Actor actorAlias = null;
var queryResult = CurrentSession.QueryOver()
.Where(r => r.StatusId == 1)
.Left.JoinQueryOver(r => r.ActorList, () => actorAlias, a => a.IsActor==1)
.List()
.Distinct()
.ToList();