简体   繁体   English

在Odata OrderBy中更改字段类型

[英]Change field type in Odata OrderBy

I have OdataService with CustDetails table (I am using Entity Framework ). 我有OdataService与CustDetails表(我使用Entity Framework )。 In the table I have column PostalCode of string type. 在表中我有列类型的PostalCode列。 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. 但我的要求是,在我的PostalCode中,所有值都只是整数值,因此我需要将数据视为整数类型来对数据进行排序。 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. 注意 :我无法更改数据库中的数据类型。

OData doesn't support conversion of primitive types in the query. OData不支持在查询中转换基元类型。 See Odata Query String Options 请参阅Odata查询字符串选项

You could, however, write a service operation to handle this for you (assuming your query provider supports this). 但是,您可以编写一个服务操作来为您处理此问题(假设您的查询提供程序支持此操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM