[英]Natural Sorting in OData $orderby Query
I'm using [EnableQuery]
(System.Web.Http.OData) in ASP.NET API 2 controllers to enable OData v3 filtering/sorting/paging. 我在ASP.NET API 2控制器中使用
[EnableQuery]
(System.Web.Http.OData)来启用OData v3筛选/排序/分页。 I've noticed that using the $orderby
clause returns data that is sorted as follows (here are some examples - they are strings and don't necessarily have a pattern to them): 我注意到,使用
$orderby
子句返回的数据按以下顺序排序(以下是一些示例-它们是字符串,不一定具有模式):
LoadTest1000_1
LoadTest1000_10
LoadTest1000_1000
LoadTest1000_2
LoadTest1000_20
[etc]
When I need natural sorting: 当我需要自然排序时:
LoadTest1000_1
LoadTest1000_2
LoadTest1000_10
LoadTest1000_20
LoadTest1000_1000
LoadTest1000_2000
[etc]
How can I enable this kind of sorting? 如何启用这种排序? Are there any extension points that I could use to provide my own sort logic?
我可以使用任何扩展点来提供自己的排序逻辑吗?
I don't think there is a nice way to do this. 我认为没有一个很好的方法可以做到这一点。 SQL Server doesn't have built in support for natural sorts in the first place.
首先,SQL Server并未内置对自然排序的支持。
That said, you might be able to use a Custom oData Function/Action. 也就是说,您也许可以使用自定义oData函数/操作。 For v3 take a look at https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/odata-actions
对于v3,请查看https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/odata-actions
Otherwise, for v4 https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions 否则,对于v4 https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions
I wish you success whoever you are random internet stranger! 无论您是随机的互联网陌生人,我祝您成功!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.