473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Please, need help to finish a query. Thank You.

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<OptionPaperOptions { 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

Sep 30 '08 #1
3 1105
On Sep 30, 1:33*am, shapper <mdmo...@gmail.comwrote:
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<OptionPaperOptions { 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 indatabase.Options on p.PollID
equals o.PollID
* * * * * * * * * * * * * * * * join v indatabase.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
Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel
Sep 30 '08 #2
I've come up with something like this:

PostPaper pp = new PostPaper();
pp.Poll = (from p in Polls where p.PollID == pollID select p).First();
var opts = (from o in Options where o.PollID == pollID select o);

OptionPaper op;
foreach (Option o in Options)
{
op = new OptionPaper();
op.Option = o;
op.Votes = (from v in Votes where v.OptionID == o.OptionID select
v).Count();
pp.Options.Add(op);
}
"shapper" <md*****@gmail.comwrote in message
news:89**********************************@l42g2000 hsc.googlegroups.com...
On Sep 30, 1:33 am, shapper <mdmo...@gmail.comwrote:
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<OptionPaperOptions { 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
Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel

Oct 1 '08 #3
On Oct 1, 3:02*am, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
I've come up with something like this:

* *PostPaper pp = new PostPaper();
* *pp.Poll = (from p in Polls where p.PollID == pollID select p).First();
* *var opts = (from o in Options where o.PollID == pollID select o);

* *OptionPaper op;
* *foreach (Option o in Options)
* *{
* * op = new OptionPaper();
* * op.Option = o;
* * op.Votes = (from v in Votes where v.OptionID == o.OptionID select
v).Count();
* * pp.Options.Add(op);
* *}

"shapper" <mdmo...@gmail.comwrote in message

news:89**********************************@l42g2000 hsc.googlegroups.com...
On Sep 30, 1:33 am, shapper <mdmo...@gmail.comwrote:
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<OptionPaperOptions { 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

Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel
I am using the following:

PollPaper paper = (from p in database.Polls
where p.PollID == id
select new PollPaper {
Poll = p,
OptionsCSV = string.Join(",",
p.Options.Select(op =op.Answer).ToArray()),
Options = (from o in p.Options
select new OptionPaper() {
Option = o,
Votes = o.Votes.Count
}).ToList()
}).SingleOrDefault();

In think it is ok ... but could someone give me some feedback?

Thanks,
Miguel
Oct 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: DD | last post by:
Hello, Could anyone please help me?? Is there somebody who could explain me how to make a connection to a access database with a python cgi script. I would like to use common sql commands in my...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
9
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a...
14
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ;...
1
by: Miguel Dias Moura | last post by:
Hello, i am creating an ASP.net / VB web site with Dreamweaver MX 2004. I have a form and a "Insert Record Behavior" to insert the form values in the database. Dreamweaver puts this code in...
4
by: Miguel Dias Moura | last post by:
Hi, I just uploaded a web site and i am getting an error. I have a script which sends form values to an email using AspNetEmail. The script was working when i was calling the script like...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.