from i in Db.Items
select new VotedItem
{
ItemId = i.ItemId,
Points = (from v in Db.Votes
where b.ItemId == v.ItemId
select v.Points).Sum()
}
我得到了这个查询,但是,如果没有发现异常的选票,它将失败:
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
我以为它是因为sum返回一个int而不是可为null的int,从而给sum一个int?由于输入仅给出相同的错误,可能导致求和仅适用于int。
有什么好的解决方法吗?