在where where condition中使用join的列

时间:2011-05-26 18:01:17

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

我使用NHibernate执行HQL:

from Contact a where IsInternal = 0

这给了我sallowing 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-condition
   ... and (contact0_1.Id is not null or contact0_2_.Id is not null)

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

最诚挚的问候,托马斯

1 个答案:

答案 0 :(得分:0)

呃,如果该字段为null,则引用的对象为null。所以:

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