Linq - Count

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    #1

    Linq - Count

    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<OptionPape rOptions { 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.Selec t(op =op.Answer).ToA rray()),
    Options = (from o in p.Options
    select new OptionPaper()
    {
    Option = o,
    Votes = o.Votes.Count,
    Share =
    o.Votes.Count / ??? *
    100
    }).ToList()
    }).SingleOrDefa ult();

    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
  • Marc Gravell

    #2
    Re: Linq - Count

    OK, given the number of times you've posted this, I think we can
    assume that there isn't a clear way to do what you want (or even,
    perhaps, understand your setup fully).

    Rather than post the same thing indefinitely, how about trying a more
    LINQ-specific forum? This isn't really a C# language question...

    For example: http://forums.microsoft.com/MSDN/Sho...D=123&SiteID=1

    Marc Gravell
    [C# MVP]

    Comment

    Working...