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,否则正式返回。 

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.

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

时间: 2024-10-06 20:24:05

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.结果类型的泛型参数或查询必须使用可空类型. 解决方法: 请确保你查询中的字段值不为空或者做为空判断 使用Ef查询出现的问题The cast to value type 'System.Boolean' failed because the materialized value is 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[,] hiveIndices = new int[,] { {200,362},{250,370},{213,410} , {400,330} , {380,282} , {437, 295} , {325, 405} , {379,413} ,{343,453} , {450,382},{510,395},{46

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

最近在研究.netcore,尝试把前后端完全分离.但是在写接口的时候,Post参数是FromBody的时候报错了 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidCastException: Unable to cast object of type

Go’s Type System Is An Embarrassment

Go is one of the best tools out there today for heavy lifting and backend code. It's my go to language when it's time to bring out the big guns and I enjoy working with it immensely. That being said, its type system is an embarrassment. It's meant to

[Hive-Tutorial] Type System 数据类型

数据类型Type System Hive supports primitive and complex data types, as described below. See Hive Data Types for additional information. Hive支持原生和复杂数据类型. Primitive Types 原生数据类型 Types are associated with the columns in the tables. The following Primitive t

无法将类型为“System.Decimal”的对象强制转换为类型“System.Char[]”。

在用微软的SSIS操作ORACLE 数据源的时候碰到以下报错信息: [ADO NET Destination [13455]] 错误: 数据插入期间出现异常,从提供程序返回的消息为:无法将类型为"System.Decimal"的对象强制转换为类型"System.Char[]". SQL语句: select A FROM TABLE WHERE B .... 字段A为NUMBER类型,但是数据库中有空值,所以报错,只是报错信息不标准 SQL改为 SELECT case

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 hierarchy and the type Nothing at the bottom of the hierarchy. All Scala types inherit from Any. # Using Any, Book extends AnyRef, and x is an Int that

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 问题描述: 再windows server 2008 r2 环境下搭建.net网站 ,运行是IIS7.0提示以上问题 解决方案: 这里需要注册一下ASP.NET 4.

fastboot 刷system.img 提示 sending 'system' (*KB)... FAILED (remote: data too large)

华为G6-C00卡刷提示OEMSBL错误,只能线刷 ,但是官方找不到线刷img镜像,无奈 网上下了个可以线刷的工具套件 流氓ROM . 使用HuaweiUpdateExtractor(工具百度)把官方 UPDATA.APP 中三个镜像文件全部提取出来 尝试使用 下面命令 fastboot flash boot boot.img fastboot flash recovery recovery.img fastboot flash system system.img 最后一步出错 提示 sendi