c# – RavenDB OrderBy

c# – RavenDB OrderBy,第1张

概述在我的C#应用​​程序中,我有一个对象集合,其int顺序属性范围从1到n. 当我喜欢这样的时候: var listings = session.Query<Listing>().Where(x => !x.IsDeleted && x.CategoryId == category.Id && x.WorkflowStatus == WorkflowStatus.Published).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).

总结

以上是内存溢出为你收集整理的c# – RavenDB OrderBy全部内容,希望文章能够帮你解决c# – RavenDB OrderBy所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1218184.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存