Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The cast to value type 'Decimal' failed because the materialized value is null

Tags:

I am having a problem with this query it's throwing an error.

var TotalToDatePayable = (  from ori in db.GetAll<WMPORI>()
                           where ori.CTMSysID == ctmSysId
                          select ori.ExB4Taxes).Sum();

I tried below code from another similar question but that did not solve my problem:

 var TotalToDatePayable = (Decimal?)(  from ori in db.GetAll<WMPORI>()
                                      where ori.CTMSysID == ctmSysId
                                     select ori.ExB4Taxes).Sum()) ?? 0;
like image 879
Developer Avatar asked May 30 '12 15:05

Developer


1 Answers

You need to cast ori.ExB4Taxes to decimal? inside the query.

var TotalToDatePayable = (from ori in db.GetAll<WMPORI>()
                          where ori.CTMSysID == ctmSysId
                          select (Decimal?) ori.ExB4Taxes).Sum() ?? 0;
like image 166
SLaks Avatar answered Oct 21 '22 17:10

SLaks