ASP.net MVC 4 (web api) OData Configuration

前端 未结 4 1577
半阙折子戏
半阙折子戏 2021-01-12 17:23

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

4条回答
  •  执念已碎
    2021-01-12 17:42

    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 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.

提交回复
热议问题