Nhibernate DetachedCriteria 子查询上的左外连接

发布于 2024-08-03 01:48:58 字数 808 浏览 2 评论 0原文

我只会尝试呈现问题的主要部分,因为整个情况要复杂得多 - 我无法使用 DetachedCriteria 实现以下目标

SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
AND _groupItemRestrictions_

可以有多个 GroupDefinitions,用户可以属于多个 GroupItems,每个 GroupItems 属于它自己组定义。由于分页/排序和(多级)组行为的一些复杂原因,我无法使用此查询实现适当的分页行为:

SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
WHERE _groupItemRestrictions_

类似于第二个查询的查询是这样生成的:

var criteria = DetachedCriteria.For<User>()
...
GroupItem groupItem = null;
criteria.CreateAlias(() => groupItemAlias, () => groupItem,
                                                JoinType.LeftOuterJoin);
criteria.Add(Restrictions.Or(...));
...

是否可以使用 DetachedCriteria 创建第一个查询?

谢谢!

I'll only try to present the main part of the problem, because the whole situation is much more complicated - I am unable to achieve the following with DetachedCriteria

SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
AND _groupItemRestrictions_

There can be multiple GroupDefinitions, User can belong to multiple GroupItems which each belong to it's own GroupDefinition. Due to some complicated reason with paging/sorting and (multilevel) group behavior, I cannot achieve appropriate paging behavior with this query:

SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
WHERE _groupItemRestrictions_

A query similar to the second one is produced this way:

var criteria = DetachedCriteria.For<User>()
...
GroupItem groupItem = null;
criteria.CreateAlias(() => groupItemAlias, () => groupItem,
                                                JoinType.LeftOuterJoin);
criteria.Add(Restrictions.Or(...));
...

Is it possible to create the first query with DetachedCriteria?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

生寂 2024-08-10 01:48:58

<罢工>
似乎还没有办法用 DetachedCriteria 指定这样的查询,但是 HQL 可以使用“with”子句:

http://fabiomaulo.blogspot.com/2009/05/nhibernate-210-hql-with-clause.html

http://www.mail-archive.com/[电子邮件受保护]/msg08451.html

更新:

https://nhibernate.jira.com/browse/NH-1946

该功能现已实现。感谢 NH 团队:)


Seems that there is no way to specify such a query with DetachedCriteria yet, but there is with HQL using a 'with' clause:

http://fabiomaulo.blogspot.com/2009/05/nhibernate-210-hql-with-clause.html

http://www.mail-archive.com/[email protected]/msg08451.html

UPDATE:

https://nhibernate.jira.com/browse/NH-1946

The feature has been implemented now. Thanks to NH team :)

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