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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:36:31+00:00 2026-06-12T06:36:31+00:00

I am trying to compute a sum of nullable int using Linq. My query

  • 0

I am trying to compute a sum of nullable int using Linq. My query looks like this:

int? surveysPromotersFromChatsGroup = (from surveyResult in surveyResultsFromChats
                                            where surveyResult.FirstScoreNPS.HasValue && surveyResult.GroupID == gr && surveyResult.FirstScoreNPS >= 9
                                            select surveyResult.FirstScoreNPS).Sum();

FirstScoreNPs field is a nullable int. My problem is that the sum always return null no matter what. I can’t see the logic behind this. I checked and I know for certain that some entities do have values in that field and the sum method should sum up those values.

Another approach that I tried is like this:

int surveysPromotersFromChatsGroup = (from surveyResult in surveyResultsFromChats
                                      where surveyResult.FirstScoreNPS.HasValue && surveyResult.GroupID == gr && surveyResult.FirstScoreNPS >= 9
                                      select surveyResult.FirstScoreNPS).Sum(score => score.Value);

But I get an exception “linq the null value cannot be assigned to a member with type”.

Isn’t there a way to sum up the non null values from that field using linq?

The surveyResultsFromChat is actually from another query:

                var surveyResultsFromChats = from surveyResult in db.SurveyResults
                                    join survey in db.Surveys on surveyResult.SurveyID equals survey.SurveyID
                                    join userGroup in db.UserGroupMaps on surveyResult.UserID equals userGroup.UserID
                                    where surveyResult.CreatedDate >= startDate && surveyResult.CreatedDate <= endDate && surveyResult.UserID.HasValue && surveyResult.ChatSessionID.HasValue
                                    select new { surveyResult.ResultID, survey.BrandID, userGroup.GroupID, surveyResult.CompletedDate, surveyResult.FirstScoreNPS };

FirstScoreNPS in my model is an Nullable int.

  • 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-06-12T06:36:33+00:00Added an answer on June 12, 2026 at 6:36 am

    you can try out

    (from surveyResult in
     surveyResultsFromChats
    where surveyResult.FirstScoreNPS.HasValue && surveyResult.GroupID == gr && 
    surveyResult.FirstScoreNPS >= 9
       select surveyResult.FirstScoreNPS).
    Select(score => score.Value ?? 0).Sum();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem: Compute the value of π using the following series: ((π^2)-8)/16=[sum from
I have been trying to compute the total sum of all these ord s
Im trying to compute a 24 hour rms (root mean squared) from a dataset
I'm trying to compute confidence intervals for groups with a common model using lmList
i'm trying to compute the Lorenz system using Runge Kutta method, but i can't
I am trying to implement: dtGroupedBy.Compute(sum(POWER),dvv.RowFilter); It results of an error: Invalid usage of
I'm trying to compute the mean value of a vector of doubles using the
I have a sum that I'm trying to compute, and I'm having difficulty parallelizing
I was trying to write a function that would compute the sum of the
i'm trying to compute 2^0 + 2^1 + 2^2 + ... + 2^14, using

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.