Mar 09, 2012 07:08 AM|awebb|LINK
If your action method returns IQueryable<TItem> then Web API itself will apply $filter, $orderby, $skip and $top OData system query options that are present in the URI's query string. This is handy because the expression language of $filter can get quite
complex, even for fairly limited subsets of the full language.
If, like me, your data source doesn't expose IQueryable<T>, then you'll have to take $skip and $top args in your action methods more directly - like this:-
public Portfolios GetPortfolios([FromUri(Prefix = "$skip")] String skip, [FromUri(Prefix = "$top")] String top)
You need the FromUri attribute to map "$skip" to a param name "skip" because C# doesn't allow params and variables starting with $.
If $skip isn't present, then skip will be null - interpret this as zero.
If $top isn't present, then top will be null - interpret this as "all items". But what I do is impose a maximum limit. I.e. if top is null or exceeds N, then set to N.