使用NHibernate ICriteria / QueryOver查询等于外连接的条件

时间:2016-10-13 08:59:34

标签: nhibernate queryover icriteria

如何在Nhibernate / QueryOver / ICriteria的外部联接中执行等于条件?

我发现将surveyRequest.Survey.IdsurveyID进行比较的唯一方法是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 }))
//                                                   ^^^^

(我正在重复使用之前的query question。)

1 个答案:

答案 0 :(得分:3)

我们可以使用.Where()

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 ))