How to find out which records have been filtered out by Queryable attribute?

只愿长相守 提交于 2019-12-13 03:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!