2中的linq中左联接

2中的linq中左联接

本文介绍了在NHibernate 3.2中的linq中左联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在NHibernate 3.2中的linq中实现左联接?

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

我想实现类似于此sql查询的linq查询:

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

我写了这样的linq查询:

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

但是我遇到了这个异常

答案:我可以使用导航属性解决此问题:

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

推荐答案

当前仅在导航属性上支持外部联接.示例:

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

from child in parent.Children.DefaultIfEmpty()

edit:对不起,似乎不在3.2中.你不能更新吗?

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

这篇关于在NHibernate 3.2中的linq中左联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:18