我想做一个"进入组查询";例如,在可以为null的外键上,基于customer.LocationId
获取客户的所有信用。但是如果customer.LocationId
为null,我希望列表为null或为空。
但是使用下面的代码,EF会忽略LocationId
为空的客户
var customers = from c in db.Customers
join lc in db.LocationCredits on c.LocationId equals lc.Id into credits
select new
{
CustomerName = c.Name,
Credits = credits
};
有什么想法吗?
您可以尝试此查询
var customers = db.Customers
.include(m=> m.Locations)
.where(m=> m.LocationId != null)
.select (m=> new {
Customername = m.Name,
Credits = Credits
})