转换为值类型'Decimal'失败,因为具体化值为null

时间:2022-11-12 17:08:56

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;

1 个解决方案

#1


23  

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

你需要将ori.ExB4Taxes转换为十进制吗?在查询中。

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

#1


23  

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

你需要将ori.ExB4Taxes转换为十进制吗?在查询中。

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