【问题标题】:Use column of join in where condition在 where 条件下使用 join 列
【发布时间】:2011-09-02 20:04:41
【问题描述】:

我使用 NHibernate 进行休闲 HQL:

from Contact a where IsInternal = 0

这给了我闲置的 sql(来自 NHProfiler):

select TOP ( 25 /* @p0 */ ) contact0_.Id                   as Id29_,
                   contact0_.ObjectVersion        as ObjectVe2_29_,
                   ...
                   ...
from   Contact contact0_
       left outer join Company contact0_1_
         on contact0_.Id = contact0_1_.Id
       left outer join Person contact0_2_
         on contact0_.Id = contact0_2_.Id
       left outer join Branch contact0_3_
         on contact0_.Id = contact0_3_.Id
       left outer join ContactGroup contact0_4_
         on contact0_.Id = contact0_4_.Id
where  contact0_.IsInternal = 0

我现在想用

扩展 where 条件
   ... and (contact0_1.Id is not null or contact0_2_.Id is not null)

现在的问题是,如何访问 HQL 中的连接表?

最好的问候,托马斯

【问题讨论】:

    标签: nhibernate join hql left-join where-clause


    【解决方案1】:

    呃,如果字段为空,那么引用的对象为空。所以:

    where IsInternal = 0 and (a.person is not null or a.company is not null)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 2012-04-14
      相关资源
      最近更新 更多