Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:02:09+00:00 2026-05-28T02:02:09+00:00

My database table has the following: ID PollID Count 1 6 0 2 6

  • 0

My database table has the following:

ID   PollID Count
1    6      0    
2    6      1

Obviously doing a: SELECT SUM([COUNT]) WHERE POLLID = 6 would return 1

However, this LINQ code is returning 2.

long totalVoteCount = (from pa2 in df.PollAnswers
                       where pa2.Poll.ID == pollID
                      select pa.Count).Sum();

While writing this question, I noticed that the above LINQ code is returning incorrect data for other queries. What exactly am I doing wrong here? I want to SUM the COUNT column for a prticular POLLID.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:02:10+00:00Added an answer on May 28, 2026 at 2:02 am

    You’re projecting pa.Count from your query instead of pa2.Count.

    Therefore, if you have a pa variable in scope that refers to an object whose Count property is 1, and there are two items in df.PollAnswers, your query will indeed always return 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
I have a following scenario in my SQL Server 2005 database. zipcodes table has
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
How to write Sql or LinqToSql for this scenario? A table has the following
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a SQL Server 2008 database. This database has a Table called Book.
I have a database with a table named shoppingcarts . this table has the
I've a database table, which has the following form catID | category | parentID
I have a table in database called user which has following entries. Userid FirstName
My SQL Server 2008 database table has a XML field. I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.