Nhibernate DetachedCriteria 子查询上的左外连接
我只会尝试呈现问题的主要部分,因为整个情况要复杂得多 - 我无法使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<罢工>
似乎还没有办法用 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.htmlUPDATE:
https://nhibernate.jira.com/browse/NH-1946
The feature has been implemented now. Thanks to NH team :)