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.
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.的更多相关文章
- 使用Ef查询出现的问题The cast to value type 'System.Boolean' failed because the materialized value is null.的解决方法
把值类型的系统.布尔的失败是因为物化值是null.结果类型的泛型参数或查询必须使用可空类型. 解决方法: 请确保你查询中的字段值不为空或者做为空判断
- 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 ...
- Unable to cast object of type 'System.Int32' to type 'System.Array'.
x 入职了新公司.最近比较忙...一看博客...更新频率明显少了...罪过罪过... 新公司用ASP.NET MVC 遇上一个错误: Unable to cast object of type 'Sy ...
- Unable to cast object of type 'System.Int32' to type 'System.String'.
最近在研究.netcore,尝试把前后端完全分离.但是在写接口的时候,Post参数是FromBody的时候报错了 Microsoft.AspNetCore.Diagnostics.DeveloperE ...
- [Hive - Tutorial] Type System 数据类型
数据类型Type System Hive supports primitive and complex data types, as described below. See Hive Data Ty ...
- log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'
使用log4net,在win7上可以正常使用,但是在部分xp电脑上可以生成access数据库,但是无法写数据到mdb 排除了程序原因,怀疑是xp缺少什么dll之类的 偶然查到log4net的调试方法: ...
- Type system
Type system[edit] Main articles: Data type, Type system, and Type safety A type system defines how a ...
- 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 ...
- 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 ...
随机推荐
- 通过Gson解析Json数据
Json是一种数据格式,便于数据传输.存储.交换:Gson是一种组件库,可以把java对象数据转换成json数据格式. gson.jar的下载地址:http://search.maven.org/#s ...
- 开源项目MultiChoiceAdapter详解(一)——概要介绍
项目地址:https://github.com/ManuelPeinado/MultiChoiceAdapter 这个项目主要是提供了一个多选适配器,使用者可以用它来替换传统的适配器,用途还算比较广泛 ...
- TextView中文文档
十分感谢农民伯伯的翻译:http://www.cnblogs.com/over140/archive/2010/08/27/1809745.html xml 属性: 属性名称 描述 android: ...
- 使用自定义的Adapter来设置ListView的内容
这里主要是学习的Adapter的机制 MainActivity.java package com.kale.listview; import android.app.Activity; import ...
- 零基础写python爬虫之使用Scrapy框架编写爬虫
网络爬虫,是在网上进行数据抓取的程序,使用它能够抓取特定网页的HTML数据.虽然我们利用一些库开发一个爬虫程序,但是使用框架可以大大提高效率,缩短开发时间.Scrapy是一个使用Python编写的,轻 ...
- Java NIO AsynchronousFileChannel
In Java 7 the AsynchronousFileChannel was added to Java NIO. The AsynchronousFileChannel makes it po ...
- jboss支持远程访问配置
jboss有个特点,在本机启动之后,只能在本机的网页访问 http://localhost:8080,在其他机器上访问不了jboss服务. 1.关闭jboss服务端的防火墙 解决方法如下: (dcm4 ...
- Lucene的查询语法,JavaCC及QueryParser(1)
http://www.cnblogs.com/forfuture1978/archive/2010/05/08/1730200.html 一.Lucene的查询语法 Lucene所支持的查询语法可见h ...
- THINKPHP 验证码不显示
最近同事将我之前使用Thinkphp做的一个项目从香港服务器迁移到国内,但却遇到了图片验证码不显示的问题 但我确认了以下可能的问题后还是没有解决 PHP是否已经安装GD库支持: 输出之前是否有任何的输 ...
- Andriod NDK assets的三个相关知识
如何获取assetManager engine->app->activity->assetManager Asset文件应该放在哪个目录? 如何生成tga文件: 可以用这 ...