使用Linq to Entities的时候发生如下异常:

Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

  1. var histroyList = data.TransMemoryHistory.Where(c => c.TransMemorys.TMID == tmid && c.UsedType != (int)usedType);

termUsedType是枚举类型。

这是因为Linq to Entities根据Where中的委托生成SQL语句,所以对里面的复杂程度(方法)有一定的限制,其中的(int)s就无法被正确翻译。但是也不完全会出现此错误。

要解 决这个问题,需要把这个(int)s过程放到外面来:

  1. int usedType = (int)termUsedType;
  2. var histroyList = data.TransMemoryHistory.Where(c => c.TransMemorys.TMID == tmid && c.UsedType != usedType);

Unable to create a constant value of type 'Closure type'的更多相关文章

  1. Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.

    代码如下: var query = from s in db.LoginUserServices join ss in db.Services on s.ServiceType equals ss.C ...

  2. Unable to create the store directory. (Exception from HRESULT: 0x80131468)

    一个ASP.NET的程序,使用了MS ReportViewer报告控件,在用该控件导出生成Excel文件时,先是提示行不能超过65535. 这个是由于Excel2003的行限制的原因.由于修改成用Ex ...

  3. JVM虚拟机宕机_java.lang.OutOfMemoryError: unable to create new native thread

    原因:当前用户的系统最最大程序数数已达到最大值,使用ulimit -u可以看到是1024   解决办法:在当前用户下使用ulimit -u 65535 然后再执行jsp,一切ok     功能说明:控 ...

  4. Fatal error in launcher Unable to create process using 'dapppythonpython37python

    Fatal error in launcher: Unable to create process using '"d:\app\python\python37\python.exe&quo ...

  5. 记一次tomcat线程创建异常调优:unable to create new native thread

    测试在进行一次性能测试的时候发现并发300个请求时出现了下面的异常: HTTP Status 500 - Handler processing failed; nested exception is ...

  6. 解决Unable to create new native thread

    两种类型的Out of Memory java.lang.OutOfMemoryError: Java heap space error 当JVM尝试在堆中分配对象,堆中空间不足时抛出.一般通过设定J ...

  7. ArcEngine编辑保存错误:Unable to create logfile system tables

    通过ArcEngine对多个SDE中多个图层进行批量编辑处理,其中有部分图层在结束编辑的时候出现错误提示(部分图层可以,只有两个数据较多的图层保存失败). 错误信息:Unable to create ...

  8. Fatal error in launcher: Unable to create process using '"'

    今天遇到了 Fatal error in launcher: Unable to create process using '"' 这个问题,原来是我上次装python3.5的时候,pyth ...

  9. Genymotion创建下载模拟器的时候出现Unable to create Genymotion virtual devices:Connection timeout错误

    如图,如果Genymotion创建下载模拟器的时候出现Unable to create Genymotion virtual devices:Connection timeout错误,具体解决方法如下 ...

随机推荐

  1. 爬虫:获取多次跳转后的页面url

    <?php $url = "xxxx"; $xx = get_headers($url,true); var_dump($xx); ?> Nbimer主页 剖面加阴影应 ...

  2. Composite模式

    1 意图:将对象组成树形结构,以表示“部分——整体”的层次结构.Composite使得用户对单个对象和组合对象的使用具有一致性. 2 动机:同意处理图元对象和包含图元的容器对象.Composite通过 ...

  3. Python之路 day2 初识字典

    #Author:ersa ''' key-value 键值对 字典是无序的,不需要下标,有key 字典的查找.修改.添加.判断.删除 ''' info = { 'stu1101': "Ten ...

  4. 【bzoj1098】办公楼

    [bzoj1098]办公楼 题意 FGD开办了一家电话公司.他雇用了N个职员,给了每个职员一部手机.每个职员的手机里都存储有一些同事的电话号码.由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄 ...

  5. Ubuntu 16.04 更新源

    1/ 在修改source.list前,最好先备份一份 执行备份命令 sudo cp /etc/apt/sources.list /etc/apt/sources.list.old 2/ 执行命令打开s ...

  6. MySQL 循环执行kill语句杀掉连接

    mysql中创建索引时,一直卡住不动,刚开始以为可能是数据量太大导致的,可是一直等了很久还是一样没有反应,看来操作的表被锁住了,执行show processlist 果然发现有大量的lock,使用ki ...

  7. Eclipse新建web项目正常启动tomcat不报错,但不能访问项目的解决方法

    原因:  虽然我手动添加了自己下载的tomcat,但是由于在Eclipse中创建Server时,"Server Locations"选项采用的时默认配置,即"Use wo ...

  8. Android碎片使用

    首先新建一个fragment的布局文件,   <?xml version="1.0" encoding="utf-8"?><LinearLay ...

  9. 什么是Angular? 我们为什么要学习它?

    在我更新Ionic的时候有人问我什么是 Angular,我们为什么要学习它啊?这个是我的疏忽了,在没有告诉你们什么是 Angular 的时候就让大家着手去学习 Ionic .那么今天就让我们认识一下什 ...

  10. Positive-definite matrix

    In linear algebra, a symmetric n × n real matrix M is said to be positive definite if zTMz is positi ...