问题
I have an asp.net web api controller for which I have enabled odata query options. The controller is as follows:
[Queryable(PageSize = 10)]
public IQueryable<MyDTO> Get(string Id)
{
//some code here
}
As obvious from the Queryable
attribute, this controller always returns 10 records at a time if there are more than 10 MyDTO's
.
How can I find out which 10 records have been returned or which records have been filtered out by odata query option?
回答1:
All pageSize does is do a Take on the queryable your action returned after the incoming $filter, $orderby, $skip, $top have been applied first. If you want to post-process the items that you return after the query is applied, you can take ODataQueryOptions<MyDTO> as input and manually apply it on the IQueryable
回答2:
public IQueryable<MyDTO> Get(string Id, ODataQueryOptions<MyDTO> queryOptions)
{
IQueryable<MyDTO> allMyDTOs = GetMyDTOs(Id);
ODataQuerySettings settings = new ODataQuerySettings() { PageSize = 10 };
IQueryable<MyDTO> appliedMyDTOs = queryOptions.ApplyTo(allMyDTOs, settings) as IQueryable<MyDTO>;
return appliedMyDTOs;
}
Here are some samples.
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options
来源:https://stackoverflow.com/questions/17847362/how-to-find-out-which-records-have-been-filtered-out-by-queryable-attribute