c# – RavenDB OrderBy

在我的C#应用​​程序中,我有一个对象集合,其int顺序属性范围从1到n.

当我喜欢这样的时候:

var listings = session.Query<Listing>().Where(x => !x.IsDeleted && x.CategoryId == category.Id && x.WorkflowStatus == WorkflowStatus.Published).OrderBy(x => x.Order);

我得到了一系列列表,但没有按正确的顺序100%.按顺序,顺序如下:

0,1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24,25,26,28,29,3,30,31,32,33,4 ....

知道为什么OrderBy没有完全按照它应该做的事情吗?

解决方法

如果使用索引,则需要为Order属性设置sortoptions.
http://ravendb.net/docs/client-api/querying/static-indexes/customizing-results-order

Numerical values,on the other hand,are stored as text and therefore require the user to specify explicitly what is the number type used so a correct sorting mechanism is enforced. This is quite easily done,by declaring the required sorting setup in SortOptions in the index deFinition:

Sort(x => x.Order,SortOptions.Int);

The index outlined above will allow sorting by value on the user’s age (1,etc). If we wouldn’t specify this option,it would have been sorted lexically (1,etc). The default SortOptions value is String. Appropriate values available for all numeric types (Byte,Double,Float,Int,Long and Short).

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...