强制转换为值类型“十进制"失败,因为实例化值为null [英] The cast to value type 'Decimal' failed because the materialized value is null
本文介绍了强制转换为值类型“十进制"失败,因为实例化值为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此查询存在问题,它引发了错误.
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;
推荐答案
您需要在查询内部将ori.ExB4Taxes
强制转换为decimal?
.
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;
这篇关于强制转换为值类型“十进制"失败,因为实例化值为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文