The below code is the second run in an Single Transfer Vote(STV) System.
' Elected Officials From Previous Count with excess votes
Dim Officials = From o In PlatoDB.ElectionCounts
Where o.Count = ElectionCount - 1 AndAlso o.Votes > Quota
Order By o.Votes Descending
If ElectionCount - 1 = 1 Then
For Each o In Officials
Dim oVotes = GetVotes(ElectionId)
Dim oInheritableVotes = From vote In oVotes
Where vote.Preference = 1 AndAlso
vote.LinkId = o.CandidateId AndAlso
vote.Vote_Headers.Used = False
Select vote.Vote_Headers
My current problem is here under where I need to group by Vote_HeaderID and the retrieve the vote with the min preference. The best I've gotten so far is the min preference and the vote's parent(Vote_HeaderId).
' Gets the next available preference which hasn't been elected
Dim NextPreference = From inheritedVote In oInheritableVotes
From v In PlatoDB.Votes
Where v.Vote_HeaderId = inheritedVote.Id AndAlso
v.Preference > 1 AndAlso
Not Officials.Select(Function(f) f.CandidateId).Equals(v.LinkId)
Group v By v.Vote_HeaderId Into Group
Select Vote_HeaderId, MinVote = Group.Min(Function(f) f.Preference)).ToList
Next
Else
End If
Does anyone have a suggestion how I could get the vote_id directly rather having to use the current list to get the actual votes.