NHibernate QueryOver with an Or subquery
Ok I'm losing on this one. I have an NHibernate query that looks something like this
var subQuery = QueryOver.Of<Lead>()
.Where(x => x.Client == user.Client)
.And(x => x.LeadType == leadType && x.LeadType != LeadTypeEnum.Self)
.Select(Projections.Distinct(Projections.Id()));
开发者_运维技巧
I use this
var query = Session.QueryOver<Lead>()
.WithSubquery.WhereProperty(x => x.Id).In(subQuery);
This produces what I need
Where lead.id in (select Id from .......)
However, I need to add another subquery. Easy to do like above, but I need this to produce the following
Where lead.id in (select id from .....)
or lead.id in (select id from .......)
The problem is I'm always getting the following
Where lead.id in (select id from .....)
and lead.id in (select id from .......)
Could someone point me in the correct direction to get the Or please
I'm an NH newbie myself , but you might want to try created a disjunction and adding the conditions to it, then adding the disjunction to the QueryOver Where
call.
var disjunction = new Disjunction();
disjunction.Add(subQuery1);
disjunction.Add(subQuery2);
var query = Session.QueryOver<Lead>()
.Where(disjunction);
精彩评论