NHibernate HQL Inner Join (SQL Server,Visual C#)

假如想象 提交于 2019-12-02 07:19:27

The point here is

  • CROSS JOIN if there are no mapped relations,
  • JOIN on existing (mapped) relations.

So, in case, there is no mapped relation Question to Answer - we still can query it like this:

// instead of INNER JOIN we use 'comma' to produce CROSS JOIN
// instead of ON we need WHERE
// string sqlQuery = "Select fq FROM Answers as fq, INNER JOIN Questions as q "+ 
//  "on fq.questionId=q.questionId";

string sqlQuery = "Select fq FROM Answers as fq, Questions as q " +
    " WHERE fq.questionId=q.questionId";

In case we have mapping Answer.Question and IList<Answer> Question.Answers

// the Reference (C#) is the way how to express ON
string sqlQuery = "Select fq FROM Answers as fq INNER JOIN fq.Questions as q";

Check the

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