我有一个 LINQ 查询。在那我需要做一些计算。一切都很好,除非在任一条件中找到空值,然后简单地为整个条件返回空值。谁能告诉我即使在条件中找到了一个空值,我怎么能返回一些值。
代码
var model =
(from q in db.Porders
select new porders()
{
Id = q.Id,
DetCount = (from amtdet in db.PoDetails
where amtdet.PoId == q.Id
select amtdet.Id).Count(),
Amount = (from amtpord in db.Porders
where amtpord.Id == q.Id
select amtpord.Freight + amtpord.Misc - amtpord.Discount
).FirstOrDefault() +
(from amtdet in db.PoDetails
where amtdet.PoId == q.Id
select amtdet.Copies * amtdet.EstUnitPrice
).Sum()
}).ToList();