使用 NHibernate ICriteria/QueryOver 查询向外连接添加条件
使用 QueryOver 或 ICriteria 查询时,有没有办法在 NHibernate 中的外连接上指定附加条件?
我需要在外连接表上添加一些额外条件,但 NHibernate 总是将它们添加到末尾的 WHERE 子句中 - 这不会获得正确的行为(请参阅 http://weblogs.sqlteam.com/jeffs/archive/2007/05/14/criteria- on-outer-joined-tables.aspx)。
我似乎找不到任何方法来使用 Criteria 或 QueryOver 语法来执行此操作...
谢谢
Is there a way to specify additional conditions on outer joins in NHibernate when querying using QueryOver or ICriteria?
I need some extra conditions on the outer join-ed table, but NHibernate always adds them to the WHERE clause at the end - which does not get the correct behaviour (see http://weblogs.sqlteam.com/jeffs/archive/2007/05/14/criteria-on-outer-joined-tables.aspx).
I can't seem to find any way to do this using Criteria or the QueryOver syntax...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可能很久以前就明白了这一点。解决方案是在 JoinAlias 方法中添加 ICriteria 参数,如下所示:
我对 aliasAccFrom 有限制,我希望 TimeTo 为 null,在最后一行代码中。
You probably figure out this long time ago. Solution is to add ICriteria parameter in JoinAlias method, like this:
I have restriction on aliasAccFrom, where i want that TimeTo is null, in last line of code.
(回答了我自己的问题 - 抱歉!)
Fabio 在 NHibernate 列表上回答了类似的查询 - 只是想我将其发布在这里。
从 NH3.0 开始,这可以通过 Criteria 实现。
HQL中的功能
http://fabiomaulo.blogspot.com/2009/05 /nhibernate-210-hql-with-clause.html
使用 Criteria 看看
CreateAlias(字符串关联路径、字符串别名、JoinType joinType、ICriterion withClause)
CreateCriteria(string AssociationPath, string alias, JoinType joinType, ICriterion withClause)
使用 QueryOver 它不可用,但这里有一个 JIRA: https://nhibernate.jira.com/browse/NH-2592
(Answered my own question - sorry!)
Fabio answered a similar query on the NHibernate list - just thought I'd post it here.
That is possible with Criteria since NH3.0.
The feature in HQL
http://fabiomaulo.blogspot.com/2009/05/nhibernate-210-hql-with-clause.html
With Criteria have a look to
CreateAlias(string associationPath, string alias, JoinType joinType, ICriterion withClause)
CreateCriteria(string associationPath, string alias, JoinType joinType, ICriterion withClause)
With QueryOver it is not available but there's a JIRA for this here: https://nhibernate.jira.com/browse/NH-2592
我尝试了以下查询并查询了
i tried the following query with query over