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 742081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:42:25+00:00 2026-05-14T08:42:25+00:00

I had the 1nd statement in my code and found it not giving an

  • 0

I had the 1nd statement in my code and found it not giving an accurate count, it was returning 1 when the correct answer is 18. To try and debug the problem I broke it out creating the 2nd statement here and the count returns 18. I just don’t see what the difference is between these two. It seems like the 1st is just more compact.

I’m currently running these two statements back to back and I’m sure that the database isn’t changing between the two.

int count = (from s in surveysThisQuarter
             where s.FacilityID == facility.LocationID
             select s.Deficiencies).Count();

vs

 var tempSurveys = from s in surveysThisQuarter
                   where s.FacilityID == facility.LocationID
                   select s;
 int count = 0;
 foreach (Survey s in tempSurveys)
     count += s.Deficiencies.Count();
  • 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-14T08:42:25+00:00Added an answer on May 14, 2026 at 8:42 am

    In the first query, you’re selecting a bunch of “sets of deficiencies” and counting how many integers you’ve got. You want to sum them instead, by the sounds of it:

    int count = (from s in surveysThisQuarter
                 where s.FacilityID == facility.LocationID
                 select s.Deficiencies.Count()).Sum();
    

    or (may generate better SQL, who knows)

    int count = (from s in surveysThisQuarter
                 where s.FacilityID == facility.LocationID
                 from x in s.Deficiencies
                 select x).Count();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a discussion with some colleagues mentioning that there are not too many
Had a code smell moment and couldn't decided if its OK for a class
Had to deploy some PHP code onto a shared server with only PHP5.2.8. All
Had a quick look here, couldn't find a duplicate (correct me if im wrong).
I had some sample code I was working on and broke the link to
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
Had a coworker ask me this, and in my brain befuddled state I didn't
I had used Server Explorer and related tools for graphical database development with Microsoft
I had been happily coding along on a decent sized solution (just over 13k
I had an idea, if I add a python .py file to my C#

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.