4

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

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

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 查询:

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

但我得到了这个例外

该方法或操作未实现。

:我能够使用导航属性解决问题:

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

2 回答 2

4

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

from child in parent.Children.DefaultIfEmpty() 

编辑:对不起,好像那不在 3.2 中。不能更新吗?

于 2012-11-29T11:47:37.850 回答
2

我能够使用导航属性解决问题:

    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();
于 2012-11-29T12:42:05.467 回答