NHibernate 对左外连接进行过滤
我遇到了 NHibernate 过滤器的问题。它工作得很好,直到我对对象进行左外连接。
例如,Deal 引用PurchaseItem,但PurchaseItem 应用了CompanyId 筛选器。
如果我想查询处理与PurchaseItem 的左连接,CompanyId 过滤器将应用在WHERE 子句中,导致不会返回任何内容。
有没有办法在连接而不是在 where 子句应用过滤器?
I am running into an issue with an NHibernate filter. It works great until I do a left outer join to the object.
For example, Deal references PurchaseItem, but PurchaseItem has a CompanyId filter applied.
If I want to query deal with a left join to PurchaseItem, the CompanyId filter is applied in the WHERE clause, causing nothing to return.
Is there a way to apply the filter at the join instead of at the where clause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过使用此过滤条件修复了此问题:
“CompanyId is NULL or CompanyId = :companyId”
这是可以的,因为 CompanyId 在 SQLServer 中不为空,所以如果我们进行外连接,我们应该只得到 NULL。
Fixed this by using this filter condition:
"CompanyId is NULL or CompanyId = :companyId"
This is ok because CompanyId is not-null in SQLServer so we should only get NULL if we are doing an outer join.
我正在寻找可空可选字段的确切问题
请注意,您的 OR 将避免使用索引,因此可能会更慢。
更新:我想我找到了解决办法:
创建过滤器时,您可以设置最后一个参数“useManyToOne”= false。这将告诉 NH 不要在连接上使用过滤器。
到目前为止看来它已经奏效了:D
I'm looking for this exact problem with nullable optional fields
Note your OR will avoid using indexes so it may be slower.
UPDATE: I think I found the fix:
When you create the filter, you can set the last parameter called "useManyToOne" = false. This will tell NH to not use the filter on the joins.
So far it seems it has worked :D