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. linux cpu 100% 脚本

    for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/d ...

  2. Restful API 的设计规范(转)

    1. URI URI 表示资源,资源一般对应服务器端领域模型中的实体类.URI规范 不用大写; 用中杠-而不用下杠_; 参数列表要encode; URI中的名词表示资源集合,使用复数形式; 资源集合与 ...

  3. Git: Push rejected 的解决方案

    Push rejected: Push to origin/master was rejected 首先,git init (在工程文件夹下) git remote add [-t <branc ...

  4. [转]PHP: 深入pack/unpack

    From : http://my.oschina.net/goal/blog/195749 http://www.w3school.com.cn/php/func_misc_pack.asp PHP作 ...

  5. SharePoint 2013 基于表单 Membership 的身份验证

    其实关于SharePoint 2013 表单身份验证网上已经有很多了,比如SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authenticatio ...

  6. 8 个基于 Lucene 的开源搜索引擎推荐

    Lucene是一种功能强大且被广泛使用的搜索引擎,以下列出了8种基于Lucene的搜索引擎,你可以想象它们有多么强大. 1. Apache Solr Solr 是一个高性能,采用Java5开发,基于L ...

  7. [leetcode]Pascal's Triangle @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle/ 题意: Given numRows, generate the first numRow ...

  8. C++ stringstream格式化输出输入探索

    - 最近在笔试时经常遇见各种输入问题,于是细心总结一波: - 首先string str; cin>>str;遇到空格结束: - 于是乎产生了getline(),可与得到一行字符串:空格自动 ...

  9. PHP操作数据库函数比较

    常用的php语法连接mysql如下 <?php $link = mysql_connect('localhost', 'user', 'password'); mysql_select_db(' ...

  10. QuickXDev插件自己主动升级后player no exist

      昨晚上QuickXDev插件执行还ok,今天打开电脑启动sublime text2后.右键run with player提示player no exist watermark/2/text/aHR ...