ASP.net MVC 4(网页API)的OData配置 [英] ASP.net MVC 4 (web api) OData Configuration
问题描述
一直与(单页APP)玩耍 BigShelf 样本。我发现非常有趣的是GetBooksForSearch法(/ API / BigShelf / GetBooksForSearch),它需要额外的 $过滤器
, $ inlinecount
, $顶部
, $跳过
寻呼和过滤的结果,这是不是在控制器present参数code:
Been playing around with the (Single Page App) BigShelf sample. I found really interesting is the GetBooksForSearch method (/api/BigShelf/GetBooksForSearch) that it takes additional $filter
, $inlinecount
, $top
, $skip
parameters for paging and filtering results, which are not present in the controller code:
public IQueryable<Book> GetBooksForSearch
(string profileIds, Sort sort, bool sortAscending)
我coudln't查找有关该控制器如何翻译和事后的结果进行过滤和更重要的是,如何配置这样的行为(例如,限制最大的结果),任何有线索?任何证件
I coudln't find any documents about how that Controller translate and filter the result afterwards and more importantly, how to configure such behavior (e.g., limit the max result), anyone have a clue?
- 更新 -
发现了MVC的Web API做的伎俩。但是,我们该如何配置呢?
Found out that MVC Web API is doing the trick. But how can we configure it?
推荐答案
有被称为一个动作筛选器属性<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.http.resultlimitattribute%28v=vs.108%29.aspx\"><$c$c>ResultLimitAttribute$c$c>你可以在它返回任何操作方法使用的IQueryable&LT; T&GT;
甚至的IEnumerable&LT; T&GT;
来限制数量数据返回。
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() {
// ...
}
这篇关于ASP.net MVC 4(网页API)的OData配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!