473,388 Members | 1,326 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,388 software developers and data experts.

Linq - Count

Hello,

I have three tables with the following columns:
Polls (PollID, Question)
Options (OptionID, PollID, Answer)
Votes (VoteID, OptionID)

Then I have two wappers around Polls and Options, named PollPaper and
OptionsPaper:
public class PollPaper {
public Poll Poll { get; set; }
public List<OptionPaperOptions { get; set; }
public string OptionsCSV { get; set; }
public int Votes { get; set; }
}

public class OptionPaper {
public Option Option { get; set; }
public int Votes { get; set; }
public double Share { get; set; }
}

I am using the following Linq query to get all information from a
poll:

PollPaper paper = (from p in database.Polls
where p.PollID == id
select new PollPaper {
Poll = p,
Votes = ?????
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,
Share =
o.Votes.Count / ??? *
100
}).ToList()
}).SingleOrDefault();

Basically, I don't know how to count the total votes on that poll and
then use it to calculate the share of each poll option ... Basiclly,
fill the ???.

Does anyone knows how to do this?

Thanks,
Miguel
Oct 7 '08 #1
1 2331
OK, given the number of times you've posted this, I think we can
assume that there isn't a clear way to do what you want (or even,
perhaps, understand your setup fully).

Rather than post the same thing indefinitely, how about trying a more
LINQ-specific forum? This isn't really a C# language question...

For example: http://forums.microsoft.com/MSDN/Sho...D=123&SiteID=1

Marc Gravell
[C# MVP]
Oct 7 '08 #2

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

Similar topics

4
by: Arthur Dent | last post by:
Hello all, I am trying to figure out how to do something in LINQ, IF I can even do it in LINQ. Online samples and such for LINQ is still a bit on the sketchy side. Here is what I want to...
22
by: paululvinius | last post by:
Hi! Testing som Linq-expressions and tried to measure performance and compare it to pre-Linq programming. The folloing two methods are functional equal but the non-Linq one is twice as fast....
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
13
by: raylopez99 | last post by:
Refer to Int32.TryParse method: http://msdn.microsoft.com/en-us/library/zf50za27.aspx if you have to, specifically this example: numericString = "10345.72" styles = NumberStyles.Integer Or...
10
by: shapper | last post by:
Hello, I create the following Linq query to select all the tags associated to Posts: viewData.TagsPapers = (from t in database.Tags select new TagPaper { Tag = t, Count = t.PostsTags.Count...
4
by: CSharper | last post by:
I have following XML <root> <Person id="1"> <Name>a</Name> </Person> <Person id="2"> <Name>b</Name> </Person> </root>
2
by: Chris | last post by:
Trying to get my head around linq. Here is what I have: Tables: OrderHeader OrderLineItem OrderSubLineItem The result set I need is: OrderHeader.Description, Count(OrderSubLineItem) as...
1
by: jbot | last post by:
I've got some pages that use linq to sql. When I look at the generated sql statements in sql server profiler, I see the same statements repeated. In the example below (from a linq data source...
5
by: Edwin | last post by:
I am trying to write an application among which one of the functions is to determine the number of unique extensions found in a directory and all of its sub directories. I am trying to use Linq to...
2
by: Andy B | last post by:
How would you find out if a linq table has 0 rows in it? I have this code: NewsContext.V_News() '*** linq table to be tested for 0 rows Any ideas?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.