Equals conditions in outer joins with NHibernate ICriteria/QueryOver query

走远了吗. 提交于 2019-12-11 03:02:33

问题


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


来源:https://stackoverflow.com/questions/40016552/equals-conditions-in-outer-joins-with-nhibernate-icriteria-queryover-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!