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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:25:20+00:00 2026-05-30T11:25:20+00:00

Hy, I want to convert a sql command into linq, but I receive the

  • 0

Hy,
I want to convert a sql command into linq, but I receive the message :

< Nullable object must have a value >

My sql query is:

 Select sum(PosList.Cantity) AS cant, sum(PosList.Value) as mysum,PosList.price,PosList.Name
 from list Inner join PosList On list.ID = PosList.FactID 
 WHERE     (list.FirID = 1) AND (PosList.Date BETWEEN '2011-02-22' AND '2012-02-22') 
 GROUP BY PosList.Name, PosList.Price ORDER BY Value DESC

My linq is:

    var w = (from item in list join itemPos in PosList   on item.ID equals itemPos.FactID      
  where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
  group itemPos by itemPos.Name into hh   
  let mysum = hh.Sum(s => s.Value)    
  let cant = hh.Sum(n => n.Cantity)   
  let price = hh.Average(i => i.Price)                                  
  orderby mysum descending  
  select new Agent("", 0, 0, "", hh.Key, "", 0, (double)price, (double)cant, (double)mysum, 0, "", "", "", "", ""));

I tried the following linq, but it did not work:

 var w = (from item in list
 join itemPos in PosList  on item.ID equals itemPos.FactID   
 where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
 group itemPos by itemPos.Name into hh   
 let mysum = hh.Sum(s => s.Value)                    
orderby mysum descending  
 select new Agent("", 0, 0, "", hh.Key, "", 0, (double)hh.Average(i =>i.Price), (double)hh.Sum(n =>n.Cantity), (double)mysum, 0, "", "", "", "", ""));   

The only linq which works ok is:

   var w = (from item in list
    join itemPos in PosList
   on item.ID equals itemPos.FactID   
    where item.FirID == this.firId && item.Date >= date_start && item.Date <= date_stop   
    group itemPos by itemPos.Name into hh   
   let mysum = hh.Sum(s => s.Value)                    
   orderby mysum descending  
  select new Agent("", 0, 0, "", hh.Key, "", 0, 0, 0, (double)mysum, 0, "", "", "", "",""));   

but I need those two values(price and cantity) also..
Thanks !

  • 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-30T11:25:21+00:00Added an answer on May 30, 2026 at 11:25 am

    So the part (double)hh.Average(i =>i.Price), (double)hh.Sum(n =>n.Cantity) causes the exception. Which means that you must add conditions to get the records where Price is not null and Cantity is not null. And add i.Price.Value and n.Cantity.Value.

    (Maybe this applies to Price or Cantity only, but I cannot tell that from your code).

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

Sidebar

Related Questions

I have following SQL query and I want to convert it to LINQ. I
I have an XML datatype and want to convert an element into a sql
I want to convert my input into a timestamp value. I have only found
I want to convert the following SQL Query to a SubSonic Query. SELECT [dbo].[tbl_Agency].[ParentCompanyID]
I want to convert all of my db stored procedures to linq to sql
I have a SQL Server 2000 database and I want to convert it to
I have to following SQL Statement that I want to conver to LINQ Select
This is on SQL Server 2008. I have several columns I want to convert
I have sql server database files (Mdf/Ldf) and i want to convert them to
I want write an win-form application to convert data from foxpro table into sql

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.