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()
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个查询,但是如果没有找到异常的投票则它会失败:
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
Run Code Online (Sandbox Code Playgroud)
我假设它因为sum返回一个int而不是一个可空的int,给一个int一个?作为输入只给出相同的错误,可能导致sum仅适用于int.
有什么好的解决方法吗?