最佳答案
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 而不是一个 nullable int,给 sum 一个 int?由于输入只给出相同的错误,可能导致 sum 只对 int 起作用。
有什么好的解决办法吗?