c# - WebAPI OData $Skip on custom IQueryable double applied -
i have implemented custom iqueryable exposed via webapi odata endpoint. structure of controller's get() rather standard:
[enablequery( allowedqueryoptions = allowedqueryoptions.count | allowedqueryoptions.filter | allowedqueryoptions.orderby | allowedqueryoptions.skip | allowedqueryoptions.top)] [odataroute] public pageresult<foo> get(odataqueryoptions<foo> queryoptions) { var bars = new queryabledata<foo>(_provider); var result = ((iqueryable<foo>)queryoptions .applyto(bars, new odataquerysettings(new odataquerysettings { enableconstantparameterization = false, ensurestableordering = false }))).tolist(); var count = _provider.count; return new pageresult<foo>(result, null, count); }
the odd behavior seeing, odata $skip in query string applied after pageresult returned. example:
- if query string contains ?$top=10&$skip=10 there no results return.
- if query string contains ?&top=12&skip=10 there (2) results returned.
what looking prevent framework(s) applying skip results set since query provider implementing skip. there odataquerysettings can set prevent double application of skip?
edit: upon further investigation, when remove $count=true query string skip (and top) function expected. leads me believe approach implementing $count=true incorrect. debugging sessions appears when $count=true in query options queryable has expression tree applied twice, once return type of long, , again without wrapping countlong expression. have tried returning count on first pass , proper queryable second pass, results in delayed application of skip expression. there seems be fundamental missing here.
while reading through github issues list came across post: odata pageresult method ignoring count parameter when using enablequery attribute #159. appears problem combination of enablequery attribute , parameterized constructor taking odataqueryoptions. using both means implement constructor query options, applying query expressions, framework apply filters can on direction applied attribute; therefore double applying things skip, top , orderby.
Comments
Post a Comment