是否可以在 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();