NHibernate HQL内部连接(SQL Server,Visual C#)
我想在内部Join中使用HQL。 但是,抛出了查询语法exception。
这是我的C#代码:
string sqlQuery = "Select fq FROM Answers as fq INNER JOIN Questions as q " + " on fq.questionId=q.questionId"; IList Result; int count = 0; try { using (ISession session = ConnectionModule.OpenSession()) { IQuery query = session.CreateQuery(sqlQuery); session.CreateCriteria(typeof(Answers)); Result = query.List(); } } catch(Exception ex) { MessageBox.Show(ex.Message+"n"+ex.InnerException); }
这里的重点是
所以,万一,没有映射关系Question
Answer
– 我们仍然可以像这样查询:
// 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";
如果我们有映射Answer.Question
和IList
// the Reference (C#) is the way how to express ON string sqlQuery = "Select fq FROM Answers as fq INNER JOIN fq.Questions as q";
检查
上述就是C#学习教程:NHibernate HQL内部连接(SQL Server,Visual C#)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1038907.html