Unable to create a constant value of type 'Closure type'
2015-11-12 20:33
639 查看
使用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.
termUsedType是枚举类型。
这是因为Linq to Entities根据Where中的委托生成SQL语句,所以对里面的复杂程度(方法)有一定的限制,其中的(int)s就无法被正确翻译。但是也不完全会出现此错误。
要解 决这个问题,需要把这个(int)s过程放到外面来:
Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
var histroyList = data.TransMemoryHistory.Where(c => c.TransMemorys.TMID == tmid && c.UsedType != (int)usedType);
termUsedType是枚举类型。
这是因为Linq to Entities根据Where中的委托生成SQL语句,所以对里面的复杂程度(方法)有一定的限制,其中的(int)s就无法被正确翻译。但是也不完全会出现此错误。
要解 决这个问题,需要把这个(int)s过程放到外面来:
int usedType = (int)termUsedType; var histroyList = data.TransMemoryHistory.Where(c => c.TransMemorys.TMID == tmid && c.UsedType != usedType);
相关文章推荐
- POJ 2031 Building a Space Station【最小生成树 Kruskal】
- Extending query processing with search components
- UIImageView 圆形
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
- UILabel UISwitch UISegmentedControl UIAlertView
- valueOf跟toString区别
- 《duilib入门到精通》- duilib概述
- NRV (named return value)
- UISwitch开关
- 《iOS Human Interface Guidelines》——Color and Typography
- String,StringBuffer与StringBuilder的区别??
- 属性动画之ValueAnimator
- 属性动画之ValueAnimator
- 属性动画之ValueAnimator
- leetcode@ [303/304] Range Sum Query - Immutable / Range Sum Query 2D - Immutable
- 单例 + UIScrollView
- easyui datagrid 单选框 效果
- rebuild过程
- 怎么修改字体粗细The valid value range is from -1.0 to 1.0
- iOS 实现圆角UITableView(group类型)