实体框架4.0:实体SQL转换操作不工作 [英] Entity Framework 4.0: Entity SQL CAST Operation Not Working

查看:116
本文介绍了实体框架4.0:实体SQL转换操作不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的投文本列,其中包含一个整数文字,为Int32查询。这里的查询:

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

不过,我得到以下消息的System.Data.EntitySqlException:

However, I get an System.Data.EntitySqlException with the following message:

输入Edm.Int32'找不到。确保所需的模式被加载,并且该命名空间被正确导入。近类型名,行1列75。

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.

根据 MSDN ,Edm.Int32应该是一个有效的类型

According to MSDN, Edm.Int32 should be a valid type.

有谁知道什么是错?

编辑:

一些试验和错误之后,我发现了以下工作:

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

是错误MSDN中的例子吗?我觉得我失去了一些东西在这里...

Are the examples in MSDN wrong? I feel like I'm missing something here...

推荐答案

如果查询与EntityCommand执行时,数据类型是电火花类型,而如果查询具有的ObjectQuery执行时,数据类型是一个CLR类型。

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.

看起来你正在执行通过的ObjectQuery的comman。

Looks like you are executing the comman via the ObjectQuery.

这篇关于实体框架4.0:实体SQL转换操作不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆