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

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

也可以用下面的方法: 

 CurrentStock = db.BillEntry.Where(b => b.GoodsId == item.GoodsId).Select(b => b.Qty).DefaultIfEmpty().Sum()

  

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.的更多相关文章

  1. 使用Ef查询出现的问题The cast to value type 'System.Boolean' failed because the materialized value is null.的解决方法

    把值类型的系统.布尔的失败是因为物化值是null.结果类型的泛型参数或查询必须使用可空类型. 解决方法: 请确保你查询中的字段值不为空或者做为空判断

  2. A const field of a reference type other than string can only be initialized with null Error [duplicate]

    I'm trying to create a 2D array to store some values that don't change like this. const int[,] hiveI ...

  3. Unable to cast object of type 'System.Int32' to type 'System.Array'.

    x 入职了新公司.最近比较忙...一看博客...更新频率明显少了...罪过罪过... 新公司用ASP.NET MVC 遇上一个错误: Unable to cast object of type 'Sy ...

  4. Unable to cast object of type 'System.Int32' to type 'System.String'.

    最近在研究.netcore,尝试把前后端完全分离.但是在写接口的时候,Post参数是FromBody的时候报错了 Microsoft.AspNetCore.Diagnostics.DeveloperE ...

  5. [Hive - Tutorial] Type System 数据类型

    数据类型Type System Hive supports primitive and complex data types, as described below. See Hive Data Ty ...

  6. log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'

    使用log4net,在win7上可以正常使用,但是在部分xp电脑上可以生成access数据库,但是无法写数据到mdb 排除了程序原因,怀疑是xp缺少什么dll之类的 偶然查到log4net的调试方法: ...

  7. Type system

    Type system[edit] Main articles: Data type, Type system, and Type safety A type system defines how a ...

  8. Beginning Scala study note(8) Scala Type System

    1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the h ...

  9. Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c

    错误: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, V ...

随机推荐

  1. Android之2次打开添加友盟统计代码,后缀会添加广告

    这里首先列明步骤, 做一个标识仅此而已. 1. 首先使用apktool来反编译你待需要加入友盟统计的apk包, 具体如何使用与配置apktool, 请参考我关于apktool配置的文章. 2. 然后自 ...

  2. spring post 图片

    @RequestMapping(value = "/post",method = RequestMethod.POST) @ResponseBody String GPost(@R ...

  3. DataGridView设置列标题不换行

    dgv.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;  //设置列标题不换行 // 设定包括Header和所 ...

  4. Orchard模块开发全接触1:起步

    在<http://www.cnblogs.com/luminji/p/3831281.html>中简单介绍了 Orchard 的模块开发,接下来,我们需要做个更复杂的例子,Orchard ...

  5. 连接MSSQL2008 Express

    (1)打开Manage Studio. (2)click on the  .\sqlexpress, select property, click security, make sure use mi ...

  6. PHP 5.4.17 发布!

    PHP 5.4.17发布.2013-07-04 经过1个RC 上个版本是2013-06-07的5.4.16.修正了大约20个Bug以及几个安全漏洞.尽管5.5.0正式版已经发布.但5.4还未停止更新. ...

  7. 奇怪吸引子---Arneodo

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  8. C++中JSON的使用详解【转】

    https://blog.csdn.net/admin_maxin/article/details/53175779 jsoncpp 主要包含三个class:Value.Reader.Writer.注 ...

  9. JS条件判断

    JavaScript 是一种可以在浏览器中运行的脚本语言,是一种弱语言(相对于C,C#,JAVA而言),只要是计算机语言就会使用到条件判断式,而JavaScript作为一种“弱”语言,它的条件判断常常 ...

  10. 图片上传前预览、压缩、转blob、转formData等操作

    直接上代码吧: <template> <div> <div class="header">添加淘宝买号</div> <div ...