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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:17:50+00:00 2026-06-04T08:17:50+00:00

When using sum with lambda in Linq to SQL using the following code: int

  • 0

When using sum with lambda in Linq to SQL using the following code:

int query = (from f in odc.RDetails
                     where f.ticketID == int.Parse(ticket.ToString())
                     select f).Sum(x => x.Rate);

I get the following error:


The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.

  • 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-04T08:17:51+00:00Added an answer on June 4, 2026 at 8:17 am

    . You have to make sure x.Rate is an int, and not an int? (an int that accepts null as a value).

    . If the query has no elements, .Sum won’t do anything and will return null. Choose a default value, let’s say 0.

    var query = from f in odc.RDetails
                where f.ticketID == int.Parse(ticket.ToString())
                select f;
    
    int result = query.Any() 
                 ? query.Sum(x => x.Rate ?? 0) // use the ?? if x.Rate is an "int?".
                 : 0; // default value you can choose.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to write the query using linq? SELECT (SELECT SUM([quantity] * [price_usd]) FROM [vi].[dbo].[SALES]
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)
I am using this code to sum values from multiple radio buttons : $(document).ready(function(){
Using LINQ on collections, what is the difference between the following lines of code?
if i have this code today to find out a sum total using LINQ:
I have the following query from p in _context.Products where p.Purchases.Sum(item => item.CCAmount) >
I'm using the code from Railscasts 189 to implement roles with Devise so I
I'm trying to do something like this: using namespace boost::lambda; using boost::thread; int add(int
I like to write synthetic query on db tables like the following: Decimal sum
I am using Devexpress 11.2 In a XtraGridView I want to show Summary SUM

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.