Avatar of Karen Wilson
Karen Wilson
Flag for United States of America

asked on 

LINQ Query returning a null value for a System.Decimal type.

Because there is no data available to sum, this code is producing a null value and throwing an error. (The null value cannot be assigned to a member with type System.Decimal which is a non-nullable value type.)

Dim getLabor1 = Aggregate id In d.tblLaborInputs _
                                         Where id.siteContract = CStr(Me.ComboBox1.SelectedItem) _
                                         And id.NASAContract = ctrNo _
                                         And id.WeekEnding >= CDate(CStr(mn & "-01-" & yr)) _
                                         And id.WeekEnding <= CDate(CStr(mn & "-" & eom & "-" & yr)) _
                                         Into Sum(id.WeeklyActuals)


I changed my code to this and a ton of other stuff but still, I get an error.

 Dim getLabor1 = From id In d.tblLaborInputs _
                                         Where id.siteContract = CStr(Me.ComboBox1.SelectedItem) _
                                         And id.NASAContract = ctrNo _
                                         And id.WeekEnding >= CDate(CStr(mn & "-01-" & yr)) _
                                         And id.WeekEnding <= CDate(CStr(mn & "-" & eom & "-" & yr)) _
                                        Aggregate xx In d.tblLaborInputs _
                                            Into Sum(id.WeeklyActuals)


I get the error:  System.Linq.IQueryable(Of <anonymous type>)' cannot be converted to 'Decimal'  

I can't figure out what I am doing wrong.  Help please!
LINQ Query.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Karen Wilson

8/22/2022 - Mon