码迷,mamicode.com
首页 > 其他好文 > 详细

The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.

时间:2018-11-16 13:31:25      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:generic   zed   try   null   value   The   tst   span   div   

 CurrentStock = db.BillEntry.Where(b => b.GoodsId == item.GoodsId).Sum(b => (decimal?)b.Qty) ?? 0,

出现这种错误是因为没有获取到数据造成的,可以使用三元判断来操作,注意Sum里的Qty应该可以为空,如果为空则返回0,否则正式返回。 

The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.

标签:generic   zed   try   null   value   The   tst   span   div   

原文地址:https://www.cnblogs.com/firstcsharp/p/9968541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!