加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – RavenDB OrderBy

发布时间:2020-12-16 01:55:09 所属栏目:百科 来源:网络整理
导读:在我的C#应用??程序中,我有一个对象集合,其int顺序属性范围从1到n. 当我喜欢这样的时候: var listings = session.QueryListing().Where(x = !x.IsDeleted x.CategoryId == category.Id x.WorkflowStatus == WorkflowStatus.Published).OrderBy(x = x.Order)
在我的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).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读