Linq - Count

S

shapper

Hello,

I have three tables with the following columns:
Polls (PollID, Question)
Options (OptionID, PollID, Answer)
Votes (VoteID, OptionID)

Then I have two wappers around Polls and Options, named PollPaper and
OptionsPaper:
public class PollPaper {
public Poll Poll { get; set; }
public List<OptionPaper> Options { get; set; }
public string OptionsCSV { get; set; }
public int Votes { get; set; }
}

public class OptionPaper {
public Option Option { get; set; }
public int Votes { get; set; }
public double Share { get; set; }
}

I am using the following Linq query to get all information from a
poll:

PollPaper paper = (from p in database.Polls
where p.PollID == id
select new PollPaper {
Poll = p,
Votes = ?????
OptionsCSV = string.Join(",",
p.Options.Select(op => op.Answer).ToArray()),
Options = (from o in p.Options
select new OptionPaper()
{
Option = o,
Votes = o.Votes.Count,
Share =
o.Votes.Count / ??? *
100
}).ToList()
}).SingleOrDefault();

Basically, I don't know how to count the total votes on that poll and
then use it to calculate the share of each poll option ... Basiclly,
fill the ???.

Does anyone knows how to do this?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top