CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Linq Query

  1. #1
    Join Date
    Feb 2005
    Posts
    7

    Question Linq Query

    Hello,

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

    I then created two Wrapper Classes:
    Code:
       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:
    Code:
          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
    Last edited by cilu; September 30th, 2008 at 01:18 AM. Reason: code tags

  2. #2
    Join Date
    Apr 2006
    Posts
    220

    Re: Linq Query

    First of all use [CODE] tags to post your code.

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Linq Query

    I think it should be: Options = { { Option = ??????, Votes = ????? }}
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured