【发布时间】:2011-04-18 09:22:47
【问题描述】:
鉴于此查询:
from s in services
select new
{
s.Id,
s.DateTime,
Class = s.Class.Name,
s.Location,
s.Price,
HeadCount = s.Reservations.Sum(r => r.PartySize), // problem here. r.PartySize is int
s.MaxSeats
}
如果服务没有任何保留,则抛出此异常:
System.InvalidOperationException:转换为值类型“Int32”失败,因为具体化值为 null。结果类型的泛型参数或查询必须使用可为空的类型。
我明白了,但是我应该怎么处理呢?我的意图是,如果没有保留,则将 HeadCount 分配为 0。
【问题讨论】:
标签: c# .net linq entity-framework orm