Entity Framework 4.0: Entity SQL CAST Operation Not Working

≯℡__Kan透↙ 提交于 2019-12-10 07:27:18

问题


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...


回答1:


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.



来源:https://stackoverflow.com/questions/4826509/entity-framework-4-0-entity-sql-cast-operation-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!