from i in Db.Items
select new VotedItem
{
ItemId = i.ItemId,
Points = (from v in Db.Votes
where b.ItemId == v.ItemId
select v.Poi
I had a similar issue and came up with the solution of getting whatever I was trying to get out of the database, do a count on those and then only if I had anything returned do a sum. Wasn't able to get the cast working for some reason so posting this if anyone else had similar issues.
e.g.
Votes = (from v in Db.Votes
where b.ItemId = v.ItemId
select v)
And then check to see if you've got any results so that you don't get null returned.
If (Votes.Count > 0) Then
Points = Votes.Sum(Function(v) v.Points)
End If