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' ...
随机推荐
- php字符串替换的几个函数
strtr() str_replace() substr_replace() preg_replace() strtr()的用法: <?php $str = "test"; ...
- 第11章 GPIO输出—使用固件库点亮LED
第11章 GPIO输出—使用固件库点亮LED 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku. ...
- 极客互联网电视不是噱头,用户体验成创维G7200核心竞争力
IT产业的迅猛发展带动了智能设备的崛起与繁荣,除已经高度普及的智能手机之外.智能电视.智能可穿戴设备等一大批新兴产品更是让消费者充分感受到了智能科技为生活所带来的变化.以智能电视为例,除了乐视 ...
- Docker的Mysql数据库:把数据存储在本地目录
Docker mysql 把数据存储在本地目录,很简单,只需要映射本地目录到容器即可 1.加上-v参数 $ docker run -d -e MYSQL_ROOT_PASSWORD=admin --n ...
- 2PC AND 3PC
一.分布式数据一致性 在分布式系统中,为了保证数据的高可用,通常会将数据保留多个副本(replica),这些副本会放置在不同的物理的机器上. (1)什么是数据一致性 在数据有多份副本的情况下,如果网络 ...
- 20155226 《网络对抗》Exp 8 Web基础
20155226 <网络对抗>Exp 8 Web基础 实践内容 1.Web前端HTML 配置环境 正常安装.启动Apache 安装:sudo apt-get install apache2 ...
- 2017-2018-2 20155231《网络对抗技术》实验五: MSF基础应用
2017-2018-2 20155231<网络对抗技术>实验五: MSF基础应用 实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 实验内容 (1)各种搜索技巧的应用 比如IP2L ...
- vue-cli 动态绑定图片失败
1.template 中引用图片,第一个为固定路径,第二个为动态绑定路径 eg: <img src="XXXXXX.png" alt=""> < ...
- Android开发——官方推荐使用DialogFragment替换AlertDialog
)比如当屏幕旋转时,AlertDialog会消失,更不会保存如EditText上的文字,如果处理不当很可能引发异常,因为Activity销毁前不允许对话框未关闭.而DialogFragment对话框会 ...
- python 回溯法 子集树模板 系列 —— 2、迷宫问题
问题 给定一个迷宫,入口已知.问是否有路径从入口到出口,若有则输出一条这样的路径.注意移动可以从上.下.左.右.上左.上右.下左.下右八个方向进行.迷宫输入0表示可走,输入1表示墙.为方便起见,用1将 ...