微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐