Search code examples
c#entity-frameworkodataodatacontroller

Change field type in Odata OrderBy


I have OdataService with CustDetails table (I am using Entity Framework). In the table I have column PostalCode of string type. When I sort the data it working fine. It sort the data by considering it as string type. But my requirement is, in my PostalCode all values are integer value only , so I need to sort the data by considering it as integer type. Is it possible to change the field data type while sorting ?

Actual sorted Result:

100,
1100,
12,
2,
200

But My expected result is

2,
12,
100,
200,
1100

Please help me to overcome this. Note: I am not able to change the data type in database.


Solution

  • OData doesn't support conversion of primitive types in the query. See Odata Query String Options

    You could, however, write a service operation to handle this for you (assuming your query provider supports this).