Click to See Complete Forum and Search --> : Linq Query


Shapper
September 29th, 2008, 11:26 PM
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

nabeelisnabeel
September 29th, 2008, 11:37 PM
First of all use [CODE] tags to post your code.

boudino
September 30th, 2008, 04:15 AM
I think it should be: Options = { { Option = ??????, Votes = ????? }}