Alexey G.
Alexey G.

Reputation: 360

Left join in linq in NHibernate 3.2

Is it possible to implement left join in linq in NHibernate 3.2 ?

I want to achive a linq query similar to this sql query:

select v.*, cp.EffectiveStart
from Visits v
join VisitServices vs on v.Id = vs.VisitId
left join CarePlans cp on cp.Id = vs.CarePlanId

I have written such linq query:

var c = (from v in EntitiesRepository
                     join vs in _visitServiceRepository on v.Id equals vs.Visit.Id
                     join cp in _carePlanRepository on vs.CarePlan.Id equals cp.Id into pp                     
                     from pl in pp.DefaultIfEmpty()
                     select new { Visit = v, EffectiveStart = pl.EffectiveStart}).ToList();

But I got this exception

The method or operation is not implemented.

Answer: I was able to fix the issue using navigation property:

    var c = (from v in EntitiesRepository
             join vs in _visitServiceRepository on v.Id equals vs.Visit.Id
             select new { Visit = v, EffectiveStart = vs.CarePlan == null ? null : (DateTime?)vs.CarePlan.EffectiveStart}).ToList();

Upvotes: 4

Views: 7711

Answers (2)

Alexey G.
Alexey G.

Reputation: 360

I was able to fix the issue using navigation property:

    var c = (from v in EntitiesRepository
             join vs in _visitServiceRepository on v.Id equals vs.Visit.Id
             select new { Visit = v, EffectiveStart = vs.CarePlan == null ? null : (DateTime?)vs.CarePlan.EffectiveStart}).ToList();

Upvotes: 2

cremor
cremor

Reputation: 6886

Outer joins are currently only supported over navigation properties. Example:

from child in parent.Children.DefaultIfEmpty() 

edit: Sorry, seems like that was not in 3.2. Can't you update?

Upvotes: 4

Related Questions