Path Expected for Join! Nhibernate Error

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

I trying to do a join and I keep getting this error

Path expected for join! [SELECT t.CourseId FROM Task as t INNER JOIN Courses as c, CoursePermissions as cp WHERE (t.CourseId = 1)]

I have

const string query = "SELECT t.CourseId FROM  Task as t INNER JOIN Courses as c, CoursePermissions as cp WHERE (t.CourseId = 1)";  var a = session.CreateQuery(query);

My Sql I am trying to achieve

SELECT     dbo.Tasks.CourseId FROM         dbo.Tasks INNER JOIN                       dbo.Courses ON dbo.Tasks.CourseId = dbo.Courses.CourseId INNER JOIN                       dbo.CoursePermissions ON dbo.Courses.CourseId = dbo.CoursePermissions.CourseId WHERE     (dbo.Tasks.CourseId = 1)

I am using nhibernate 3.1 and fluent nhibernate 1.2

回答1:

It means that you using an inner join in HQL works a little different than using it in SQL. In HQL you join the tables by providing the "path", which is basically the referenced property of your class.

So instead of

SELECT t.CourseId FROM Task as t INNER JOIN Courses as c ...

you need to write

// c.Taks is the IList property in your Courses class SELECT t.CourseId FROM Courses as c INNER JOIN c.Tasks as t ...


回答2:

Although Florian Lim has suggested a great solution but in my case I didn't had IList for Tasks in Courses. I achieved that through Theta-Style Joins which actually is Cartesian product provide all possible combinations which can be filtered (in where clause) according to need.



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