预计加入路径!休眠错误

发布于 2024-11-02 22:34:56 字数 758 浏览 1 评论 0原文

我尝试进行连接,但不断收到此错误

加入的预期路径! [选择 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-11-09 22:34:56

这意味着在 HQL 中使用内部联接与在 SQL 中使用它的工作方式略有不同。在 HQL 中,您通过提供“路径”来连接表,这基本上是类的引用属性。

所以

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

你需要写

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

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 ...
一个人的夜不怕黑 2024-11-09 22:34:56

虽然 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文