|
-
September 29th, 2008, 11:26 PM
#1
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
-
September 29th, 2008, 11:37 PM
#2
Re: Linq Query
First of all use [CODE] tags to post your code.
-
September 30th, 2008, 04:15 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|