NHibernate (+ FluentNhibernate): Join two separate tables

'tI is having problems creating a connection on two objects with a common property, but they do not appear together.

Suppose you have an Article entity that contains a FamilyCode property and a Family entity with Code and Label properties.

In my mappings, the article does not reference the family and I do not want to change it (in order to maintain compatibility with other internal and inherited methods).

So, I cannot translate the following query into Nhibernate:

SELECT f.Code, f.Label
FROM Article a
INNER JOIN Family f ON a.FamilyCode = f.Code
WHERE f.Label LIKE 'p%'

      

I cannot use JoinQuery because I cannot enter QueryOver and I do not know if this is possible with WithSubquery.

I tried Future QueryOver and QueryOver and then did in-memory concatenation (after .List ()), but I have too many lines to write, so it takes a long time.

Do you have any ideas?

Thank.

+3


source to share


1 answer


We can use HQL but only HQL.

Multiple classes may appear, resulting in a Cartesian product or cross join.

from Formula, Parameter
from Formula as form, Parameter as param

      



This will be the case with HQL

SELECT f.Code, f.Label
FROM Article a,
     Family f 
WHERE a.FamilyCode = f.Code
AND f.Label LIKE 'p%'

      

Also check this 9.3.2. IQuery interface and maybe it's Q and A

+2


source







All Articles