1
votes

Doe's anybody knows how can I do join with multiple conditions in LINQ to NHIBERNATE? Join with one condition looks like this:

var Query = from p in Session.Parent
   join c in child on p.id equals c.parent_id
   select p

My sql query is:

Select *
from parent t1
left join Child t2 
    on t1.id = t2.parent_id
    and t2.age > 18

I found a syntax of multiple conditions for LINQ to SQL and it works (I tried in LinqPad) but when I'm trying to execute this code in nHibernate I'm getting exception: "The method or operation is not implemented". The syntax for LINQ to SQL is:

var Query = from p in Session.Parent
    join c in child on p.id equals c.parent_id into pc
    from pcg in pc.Where(c => c.age > 18)
    select p.PigProductid

It seems that this feature is not implemented yet in LINQ to NHIBERNATE, but maybe I'm wrong (and i hope I am).

1
yes, nhibernate's LINQ provider makes me sad sometimes. - Nagg

1 Answers

0
votes

Easiest way would be to have a reference or a collection to the children in the parent class.

maybe the following could work

var query = from p in Session.Parent
            from c in Session.Child.Where(c => c.age > 18)
            where p.Id == c.parent_id
            select p.PigProductid;