Equals conditions in outer joins with NHibernate I

2019-07-14 01:59发布

问题:

How do I do a equals condition in an outer join in Nhibernate/QueryOver/ICriteria?

The only way I have found to compare surveyRequest.Survey.Id with surveyID below is with IsIn.

SystemUser systemUser= null;
SurveyRequests surveyRequest = null;

var query = Session.QueryOver<SystemUser>(() => systemUser)
    .Left.JoinAlias(
        () => systemUser.SurveyRequests, 
        () => surveyRequest,
        Restrictions.On(()=>surveyRequest.Survey.Id).IsIn(new object []{surveyID }))
//                                                   ^^^^

(I am reusing an earlier query question.)

回答1:

We can use the .Where() part of Restrictions

var query = Session.QueryOver<SystemUser>(() => systemUser)
    .Left.JoinAlias(
        () => systemUser.SurveyRequests, 
        () => surveyRequest,
        //Restrictions.On(()=>surveyRequest.Survey.Id).IsIn(new object []{surveyID }))
        Restrictions.Where(()=>surveyRequest.Survey.Id == surveyID ))