Equals conditions in outer joins with NHibernate I

2019-07-14 01:39发布

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条回答
smile是对你的礼貌
2楼-- · 2019-07-14 01:58

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 ))
查看更多
登录 后发表回答