How to find out which records have been filtered o

2019-08-29 02:51发布

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?

2条回答
劫难
2楼-- · 2019-08-29 03:00

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

查看更多
smile是对你的礼貌
3楼-- · 2019-08-29 03:06
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

查看更多
登录 后发表回答