How can i get List along with child list where child list having some condition in NHibernate

57 views Asked by At

I had written a Query in NHibernate as below:

var queryResult = CurrentSession.QueryOver()
                                .Where(r => r.StatusId == 1)
                                .JoinQueryOver(a => a.ActorList)
                                .Where(s=>s.IsActor==1)
                                .List()
                                .Distinct()
                                .ToList();

I am trying to retrieve only Where(s=>s.IsActor==1), But It Is Getting Records Where(s=>s.IsActor==0) also...

How can I get only IsActor==1 records?

Thanks in Advance

1

There are 1 answers

0
jenson-button-event On BEST ANSWER

You need to specify a predicate in the join, so that it is applied to the join not the top where:

(will look something like ...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();