Been playing around with the (Single Page App) BigShelf sample. I found really interesting is the GetBooksForSearch method (/api/BigShelf/GetBooksForSearch) that it takes ad
It appears that the ResultLimitAttribute has been removed. See this commit
It was rolled into a feature of the [Queryable] attribute which is now required for OData support. See discussion here
Proper Usage would now be
[Queryable(ResultLimit = 10)]
[UPDATE]
As of RTM the ResultLimit feature of Queryable has been removed. Also, [Queryable] has been moved to it's own preview package. See this blog post for more information and this post for instructions on the new usage.
[UPDATE 2 11-16-12] With the ASP.Net Fall 2012 Update Preview things have been updated again. The ResultLimit Property of The [Queryable] attribute has been added back to the OData package.
See article here for a run down of some of the changes.
Here is the updated Nuget package. As of this writing it is a PREVIEW package.
There's an action filter attribute called ResultLimitAttribute which you can use on any action method which returns IQueryable<T>
or even IEnumerable<T>
to limit the amount of data returned.
[ResultLimit(100)]
public IQueryable<Product> Get() {
// ...
}
As Cody Clark pointed out, this area has seen quite a number of changes over time. As of the 5.2 version of WebAPI, you now use the EnableQueryAnnotation
and use the PageSize
parameter rather than QueryableAttribute
or ResultLimit
. ([Queryable]
will still work, but it is marked as obsolete.) Currently you would use the following syntax:
[EnableQuery(PageSize = 20, MaxTop = 20)]
public IQueryable<Product> Get() {
// ...
}
By using PageSize
, you set the default page size for unparameterized requests. If you don't include the MaxTop
value, a rogue client could set the top to a very high value and bypass the page defaults. With MaxTop
, you will throw an exception if the client requests more records than your API supports.
There is a short webcast about paging and querying with MVC Web API that you can watch here
It explains how you can perform paging by either
pageIndex
and pageSize
, and then returns the requested number of items.AFAIK, you cannot configure the maximum number of items returned by using the first method, but you could limit the number of items returned by using the second approach, and just checking if (pageSize>maxPage) then return maxPage items
.