Использовать столбец соединения в условии, где - PullRequest
0 голосов
/ 26 мая 2011

Я выполняю следующий HQL с NHibernate:

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?

С наилучшими пожеланиями, Томас

1 Ответ

0 голосов
/ 30 мая 2011

Э-э, если поле имеет значение null, то указанный объект имеет значение null. Итак:

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

...