Adding conditions to outer joins with NHibernate ICriteria/QueryOver query

强颜欢笑 提交于 2019-11-29 08:32:08

You probably figure out this long time ago. Solution is to add ICriteria parameter in JoinAlias method, like this:

Party aliasParty = null;
Party aliasPartyFrom = null;
var parties = QueryOver.Of<Party>(() => aliasParty)
              .Left.JoinAlias(
                               () => aliasParty.AccountabilitiesFrom, 
                               () => aliasAccFrom, 
                               Restrictions.On(() => aliasAccFrom.TimeTo).IsNull)

I have restriction on aliasAccFrom, where i want that TimeTo is null, in last line of code.

James Crowley

(Answered my own question - sorry!)

Fabio answered a similar query on the NHibernate list - just thought I'd post it here.

That is possible with Criteria since NH3.0. The feature in HQL http://fabiomaulo.blogspot.com/2009/05/nhibernate-210-hql-with-clause.html

With Criteria have a look to CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause) CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause)

With QueryOver it is not available but there's a JIRA for this here: https://nhibernate.jira.com/browse/NH-2592

Ivix4u

i tried the following query with query over

SystemUser systemUser= null;
SurveyRequests SurveyRequests = null;

var Query2 = Session.QueryOver<SystemUser>(() => systemUser)
               .Left.JoinAlias(() => systemUser.SurveyRequests, 
               () => surveyRequest,
               Restrictions.On(()=>surveyRequest.Survey.Id).IsIn(new object []{surveyID }))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!