linq - Enforce ordering of OData items even when $top is used -


i have dbset<items> collection.

the primary key guid. don't want order primary key. want order editable decimal property named "order".

the code have simple, , works great until user puts "$top" parameter request:

public class itemscontroller : apicontroller {     protected dbcontext ctx = // ...      // api/documents     [enablequery()]     public iqueryable<item> get() {     return ctx.items.orderby(o => o.order).asqueryable(); } 

when user puts "$top" query string, order gets messed (it presumably forces ordering done primary key, consistent paging results -- however, in situation, having opposite effect, it's preventing me having consistent paging results).

i've tried moving .asqueryable() earlier in query (before .orderby(...) clause), i've tried without .asqueryable(), i've tried 2 asqueryables, etc.

there going lot of items in table, needs done via iqueryable (enumerating of items on web server via ienumerable not option here).

the thing has worked far passing in "$orderby=order" client, don't want force (seems forgotten easily).

1.) there can make ordering order property default behavior here?

2.) or failing that, there anyway trick webapi / odata thinking custom "$orderby=order" clause specified?

to override default sort order, need set property ensurestableordering of enablequeryattribute false, describe here:

a true value indicates original query should modified when necessary guarantee stable sort order. false value indicates sort order can considered stable without modifying query. query providers ensure stable sort order should set value false. default value true.

so in code, changes action attribute this:

// api/documents [enablequery(ensurestableordering = false)] public iqueryable<item> get() {     return ctx.items.orderby(o => o.order).asqueryable(); } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -