none
Please, need help to finish a query. Thank You RRS feed

  • Question

  • Hello,

    I have three tables: Polls (PollId, Question), Options (OptionID, Answer) and Votes (VoteID, OptionID)


    I then created two Wrapper Classes:

      

      PostPaper with the following properties:
          public Poll Poll { get; set; }
          public List<OptionPaper> Options { get; set; }
          public string OptionsCSV { get; set; }

     

       OptionPaper with the following properties:
          public Option Option { get; set; }
          public int Votes { get; set; }


    I need, given an PollId, to get fill a PostPaper with all its options and for each option count the votes:


          pollViewData.PollPaper = (from p in database.Polls
                                    join o in database.Options on p.PollID equals o.PollID
                                    join v in database.Votes on o.OptionID equals v.OptionID
                                    where p.PollID == id
                                    group o by p into pog
                                    select new PollPaper {
                                      Poll = pog.Key,
                                      Options = new List<OptionPaper> {
                                        Option = ??????
                                        Votes = ?????
                                      }.ToList(),
                                      OptionsCSV = string.Join(", ", pog.Select(o => o.Answer).ToArray())
                                    }).SingleOrDefault();


    I am having problems in creating the Option and Count the votes of each OptionPaper in List Options.


    Could someone, please, help me out?

    Thanks,
    Miguel
    Tuesday, September 30, 2008 12:41 AM