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?作为输入传递给sum仍会得到相同的错误,可能是因为sum只适用于整数。
这个问题有好的解决方法吗?