Linq query with nullable sum
问题 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() } I got this query, however it fails if no votes are found with exception: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type. I assume its because sum returns an int and not a nullable int, giving sum a int? as input only give the same error, probably cause sum only workes on ints. Any good workaround