NHibernate HQL Inner Join (SQL Server,Visual C#) -
i want using hql inner join. but, query syntax exception thrown.
this c# code:
string sqlquery = "select fq answers fq inner join questions 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); }
the point here is
- cross join if there no mapped relations,
- join on existing (mapped) relations.
so, in case, there no mapped relation question answer - still can query this:
// instead of inner join use 'comma' produce cross join // instead of on need // string sqlquery = "select fq answers fq, inner join questions q "+ // "on fq.questionid=q.questionid"; string sqlquery = "select fq answers fq, questions q " + " fq.questionid=q.questionid"; in case have mapping answer.question , ilist<answer> question.answers
// reference (c#) way how express on string sqlquery = "select fq answers fq inner join fq.questions q"; check the
- 14.2. clause (details cross join)
- 14.3. associations , joins (standard join related references)
Comments
Post a Comment