Entity Framework 4.0: SQL CAST operation not working

I am trying to make a query in which I pass a text column that contains an integer as text in Int32. Here's the request:

SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5 

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

Could not find type "Edm.Int32". Be sure to load the necessary schemas and import the correct names. Next to the type name, row 1, column 75.

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

Does anyone know what is 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 MSDN examples wrong? I feel that something is missing here ...

+4
source share
1 answer

If the query is executed with EntityCommand, the data type is an EDM type, and if the query is executed with ObjectQuery, the data type is the CLR type.

It looks like you are executing comman via ObjectQuery.

+5
source

Source: https://habr.com/ru/post/1337445/


All Articles