EntityFramework异常The specified cast from a materialized 'System.Double' type to the 'System.Single' type is not valid.
实体类:
public class ReportEntity
{
public string FactorName { get; set; }
public double MaxVal { get; set; }
public double MinVal { get; set; }
public double AvgVal { get; set; }
public string UpdateTime { get; set; }
public string Unit { get; set; }
public int DecimalDigit { get; set; }
}
SQL语句
string sqlstr = " select b.FactorName,cast(MAX(a.Val) as float) as MaxVal,cast(MIN(a.Val) as float) as MinVal,cast(AVG(a.Val) as float) as AvgVal,"
+ strTime + " as UpdateTime,b.Unit,b.DecimalDigit "
+ " from Instrument_Data a,Factor b "
+ " where a.UpdateTime between '" + dtBegin + "' and '" + dtEnd + "' "
+ " and a.FactorID = b.FactorID "
+ " group by b.FactorName,b.Unit, " + strTime + ",b.DecimalDigit "
+ " order by b.FactorName,b.Unit," + strTime + ",b.DecimalDigit ";
using (var db = new DAL.WSIPCContext())
{
var result3 = db.Database.SqlQuery<Entity.ReportEntity>(sqlstr);
this.lsvData.Items.Clear();
foreach (Entity.ReportEntity i in result3)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = i.UpdateTime;
item.SubItems.Add(i.FactorName);
string format = "#0.".PadRight(i.DecimalDigit + 3, '0');
item.SubItems.Add(i.MaxVal.TryToDoubleStr(format));
item.SubItems.Add(i.MinVal.TryToDoubleStr(format));
item.SubItems.Add(i.AvgVal.TryToDoubleStr(format));
item.SubItems.Add(i.Unit);
this.lsvData.Items.Add(item);
}
}
将double换成float出现错误。EF使用System.Double对应SQLServer中的float。
重点关注:此处对SQL语句的结果也有要求,结果必须转换为float,才能与实体类映射成功!
EntityFramework异常The specified cast from a materialized 'System.Double' type to the 'System.Single' type is not valid.的更多相关文章
- entity framework异常 The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid
ROW_NUMBER() OVER (ORDER BY (select Null)) AS Id entity framework 查询中有这句会有异常
- 异常:unity3d ArgumentException: The Assembly System.Configuration is referenced by System.Data.
异常:ArgumentException: The Assembly System.Configuration is referenced by System.Data. But the dll is ...
- 异常:System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)
异常:System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid) 原因:该引用所需.NET Framework版本为4.5 ...
- Java-maven异常-cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突
使用maven开发web应用程序, 启动的时候报错: jar not loaded. See Servlet Spec . Offending class: javax/servlet/Servlet ...
- EntityFramework 异常 -- An entity object cannot be referenced by multiple instances of IEntityChangeTracker
问题 在调用 DbSet 的 Attach() 方法时(与将 Entity 设置为 EntityState.Unchanged 状态等价)报告以下错误: An entity ob ...
- 异常: Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' is expected to be of type 'org.aopalliance.aop.Advice' but was actually of type 'org.springframework.transaction.i
场景: 在使用spring整合hibernate事务时报错解决: spring-aop中已经包含aopaliance,删除多余的jar包
- Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch6'.
VS 里面的Interop.Shell32.dll(1.0) 这个版本太低了,需要高版本的(我使用的是1.2.107.0) 具体下载地址 自己找吧
- EF添加Msysql实体异常:表“TableDetails”中列“IsPrimaryKey”的值为 DBNull。 ---> System.InvalidCastException: 指定的转换无效。
尝试一下以下步骤: 1.关闭VS项目, 以管理员权限来打开: 1.执行语句 set global optimizer_switch='derived_merge=OFF'; set optimizer ...
- ssm裤架搭建异常: Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' ...
随机推荐
- Android自定义布局的背景在多分辨率的情况下设置fill_parent时背景不能够横向全屏的问题解决
问题描述:最近做了一个自定义的控件LinearLayout就是公用的底部菜单条,在指定分辨率下(例如:480x800,480x854)下背景是正常的,但是当程序运行到非指定(默认)的分辨率下就不正常了 ...
- 关于Android开发环境的演变
是不是我天生就不适合安装软件——经过eclipse.jdk.Android Studio的历次安装,我发觉自己似乎永远都装不好.去年eclipse断断续续装了三四天,那时希望能附加C++的软件包,却始 ...
- 【转】MySQL执行计划分析
原文:http://www.cnblogs.com/wangyanhong/archive/2013/09/18/3327919.html 一.语法explain <sql语句>例如: e ...
- Mapnik初学笔记
前言:夏天总是感觉想要睡觉,一心想颓废的我却要一周六天都要处于工作状态,但有些事虽然麻烦,但还是要去做,不由得想起火影忍者里面鹿丸这一个角色,有时候真能理解他的心理状态,或许我应该向他学习:善于思考的 ...
- 感言&3
- redis系列--深入哨兵集群
一.前言 在之前的系列文章中介绍了redis的入门.持久化以及复制功能,如果不了解请移步至redis系列进行阅读,当然我也是抱着学习的知识分享,如果有什么问题欢迎指正,也欢迎大家转载.而本次将介绍哨兵 ...
- 20155317 十六周second 取值
20155317 十六周second 取值 题目如下图: secondset #define base 0xFFFFC0000 # #define &clock void setsecond( ...
- 汇编 for循环
知识点: for循环生成代码1 for循环生成代码2 inc指令 一.一般情况下的for循环汇编代码分析 ;i<=;i++) { printf("%d,",i); } ...
- python 网络爬虫requests模块
一.requests模块 requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效. 1.1 模块介绍及请求过程 requests模块模 ...
- effective c++ 笔记 (31-34)
//---------------------------15/04/20---------------------------- //#32 确定你的public继承塑膜出 is-a 关系 { ...