Unable to create a constant value of type 'Closure type'.异常
来源:互联网 发布:mysql免安装版配置教程 编辑:程序博客网 时间:2024/06/06 14:29
使用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.
代码是这样的:
ctx.Products.Where(p => p.Status == (int)s).ToString();
其中s是类型为ProdcutStatus的枚举类型:
public enum ProdcutStatus{
Open,
Close
}
这是因为Linq to Entities根据Where中的委托生成SQL语句,所以对里面的复杂程度(方法)有一定的限制,其中的(int)s就无法被正确翻译。
要解决这个问题,需要把这个(int)s过程放到外面来:
int status = (int)s;
ctx.Products.Where(p => p.Status == status).ToString();
这样Where内部还是保持了相对的“干净”,不会阻碍SQL语句的动态生成。
- Unable to create a constant value of type 'Closure type'.异常
- EF中Unable to create a constant value of type...的错误解决
- Unknown debugger type "No engine" Unable to create a debugger engine of the type "No engine"
- 异常:Null value was assigned to a property of primitive type setter of···
- hibernate异常Null value was assigned to a property of primitive type setter
- spring 事务异常Failed to convert property value of type [$Proxy12] to required type
- SSH 项目异常:Failed to convert property value of type [$Proxy13] to required type
- 异常处理:Null value was assigned to a property of primitive type setter of"原因及解决方案
- Unable to infer closure return type in current contentx
- Cannot assign value of type 'InterfaceController' to type 'HKWorkoutSessinDelegate'
- Cannot assign value of type 'AnyObject' to type 'HereIsTheTypeName?'
- a value of type "const struct Menu * "cannot be assigned to an entity of type "struct Menu"
- 类似Build Error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
- Null value was assigned to a property of primitive type setter of
- Null value was assigned to a property of primitive type setter of
- Null value was assigned to a property of primitive type setter of
- Null value was assigned to a property of primitive type setter of
- Null value was assigned to a property of primitive type setter of
- /LGC图形渲染/常见颜色深度的 bitmap 之间的相互转换
- HttpModule和Http Handler (比较与区别)
- height高度100%在ie中的问题
- 丢掉宝石的孩子-谈谈我最近的感悟!
- 关于多线程编程
- Unable to create a constant value of type 'Closure type'.异常
- 著名的自由软件圣战- “KDE/QT .VS. Gnome/Gtk”
- /LGC图形渲染/Working with 16-bit RGB
- 洒洒水
- wince下流式驱动的编写
- 用typelist实现RUNTIMECLASS机制
- poi方式将数据导出到execl并提供下载
- /LGC图形渲染/Image Processing with gluas
- 转:How to implement COMET with PHP