实体类:

    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.的更多相关文章

  1. 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 查询中有这句会有异常

  2. 异常: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 ...

  3. 异常:System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)

    异常:System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid) 原因:该引用所需.NET Framework版本为4.5 ...

  4. 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 ...

  5. EntityFramework 异常 -- An entity object cannot be referenced by multiple instances of IEntityChangeTracker

    问题      在调用 DbSet 的 Attach()  方法时(与将 Entity 设置为 EntityState.Unchanged 状态等价)报告以下错误:      An entity ob ...

  6. 异常: 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包

  7. Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch6'.

    VS 里面的Interop.Shell32.dll(1.0) 这个版本太低了,需要高版本的(我使用的是1.2.107.0) 具体下载地址  自己找吧

  8. EF添加Msysql实体异常:表“TableDetails”中列“IsPrimaryKey”的值为 DBNull。 ---> System.InvalidCastException: 指定的转换无效。

    尝试一下以下步骤: 1.关闭VS项目, 以管理员权限来打开: 1.执行语句 set global optimizer_switch='derived_merge=OFF'; set optimizer ...

  9. 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' ...

随机推荐

  1. JS兼容各个浏览器的本地图片上传即时预览效果

    JS兼容各个浏览器的本地图片上传即时预览效果 很早以前 在工作曾经碰到这么一个需求,当时也是纠结了很久,也是google了很久,没有碰到合适的demo,今天特意研究了下这方面的的问题,所以也就做了个简 ...

  2. 20155237 《JAVA程序设计》实验二(JAVA面向对象程序设计)实验报告

    20155237 <JAVA程序设计>实验二(JAVA面向对象程序设计)实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S ...

  3. Android开发——断点续传原理以及实现

    0.  前言 在Android开发中,断点续传听起来挺容易,在下载一个文件时点击暂停任务暂停,点击开始会继续下载文件.但是真正实现起来知识点还是蛮多的,因此今天有时间实现了一下,并进行记录.本文原创, ...

  4. Android开发——官方推荐使用DialogFragment替换AlertDialog

    )比如当屏幕旋转时,AlertDialog会消失,更不会保存如EditText上的文字,如果处理不当很可能引发异常,因为Activity销毁前不允许对话框未关闭.而DialogFragment对话框会 ...

  5. Vue 项目集合

    饿了么安全应急响应中心 饿了么招聘 饿了么前端 · GitHub 稀土掘金 异乡好居 明星垂搜 广州建管 基于Vue.js的数据统计系统(一) 基于Vue.js的数据统计系统(二) 基于Vue.js的 ...

  6. java 锁白话

    一.锁 1.可见性: 定义:数据对所有线程可见 原因:cpu操作数据时会把数据读取到内存中去,可以理解为值做了备份,但是备份数据和原始数据在后续操作中不一定一致 实现:java使用volite关键字来 ...

  7. python编码你需要知道的编码风格

    此时你已经可以写一些更长更复杂的 Python 程序,是时候讨论一下 编码风格 了.大多数语言可以写(或者更明白的说, 格式化 )作几种不同的风格.有些比其它的更好读.让你的代码对别人更易读是个好想法 ...

  8. vuex实践之路——笔记本应用(三)

    Actions Action 类似于 mutation,不同在于: Action 提交的是 mutation,而不是直接变更状态. Action 可以包含任意异步操作. 让我们来注册一个简单的 act ...

  9. <转>性能测试浅谈

    本文主要针对WEB系统的性能测试.不涉及具体的执行操作,只是本人对性能测试的一点理解和认识. 性能测试的目的,简单说其实就是为了获取待测系统的响应时间.吞吐量.稳定性.容量等信息.而发现一些具体的性能 ...

  10. Google I/O 2018大会小结

    Google I/O 2018大会于北京时间5月9日凌晨1点,在美国山景城Shoreline Amphitheatre(圆形剧场)举办.看了一下录播,字幕延迟,全程靠听,下面对上午的主会进行一个小结. ...