Left join in linq in NHibernate 3.2

坚强是说给别人听的谎言 提交于 2019-12-23 13:28:44

问题


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();

回答1:


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?




回答2:


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();


来源:https://stackoverflow.com/questions/13624959/left-join-in-linq-in-nhibernate-3-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!