预计加入路径!休眠错误
我尝试进行连接,但不断收到此错误
加入的预期路径! [选择 t.CourseId FROM 任务作为 t INNER JOIN 课程为 c,CoursePermissions 为 cp WHERE (t.CourseId = 1)]
我有
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);
我的 Sql 我正在尝试实现
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)
我正在使用 nhibernate 3.1 和流畅的 nhibernate 1.2
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着在 HQL 中使用内部联接与在 SQL 中使用它的工作方式略有不同。在 HQL 中,您通过提供“路径”来连接表,这基本上是类的引用属性。
所以
你需要写
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
you need to write
虽然 Florian Lim 提出了一个很好的解决方案,但就我而言,我没有用于课程中任务的 IList。我通过 Theta-Style Joins 实现了这一点,实际上是 笛卡尔积提供了所有可能的组合,可以根据需要进行过滤(在where子句中)。
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.