实体框架 4.0:Entity SQL CAST 操作不起作用
我正在尝试进行查询,将包含整数作为文本的文本列转换为 Int32。这是查询:
SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5
但是,我收到 System.Data.EntitySqlException 并显示以下消息:
找不到类型“Edm.Int32”。确保加载所需的架构并正确导入命名空间。靠近类型名称,第 1 行,第 75 列。
根据 MSDN,Edm .Int32 应该是有效类型。
有谁知道出了什么问题吗?
编辑:
经过一番尝试和错误,我发现以下方法有效:
SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS System.Int32) > 5
MSDN 中的示例是否错误?我感觉我在这里失去了一些东西......
I'm trying to make a query where I cast a text column, which contains an integer as text, to an Int32. Here's the query:
SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5
However, I get an System.Data.EntitySqlException with the following message:
Type 'Edm.Int32' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 75.
According to MSDN, Edm.Int32 should be a valid type.
Does anyone know what's wrong?
Edit:
After some trial and error, I found that the following works:
SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS System.Int32) > 5
Are the examples in MSDN wrong? I feel like I'm missing something here...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果使用 EntityCommand 执行查询,则数据类型为 EDM 类型,而如果使用 ObjectQuery 执行查询,则数据类型为 CLR 类型。
看起来您正在通过 ObjectQuery 执行命令。
If a query is executed with the EntityCommand, the data type is an EDM type, while if the query is executed with ObjectQuery, the data type is a CLR type.
Looks like you are executing the comman via the ObjectQuery.