[英]Entity Framework into group query with nullable foreign key
我想做一個外鍵可以為空,例如“成組查詢”,讓所有學分根據客戶customer.LocationId
。 但如果customer.LocationId
為空,我希望列表為空或空。
但是使用下面的這段代碼,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
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.