如何找出哪些记录由Queryable已经被过滤掉的属性? [英] How to find out which records have been filtered out by Queryable attribute?

查看:185
本文介绍了如何找出哪些记录由Queryable已经被过滤掉的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我所启用ODATA查询选项一个asp.net网页API控制器。控制器如下:

  [可查询(每页= 10)]
公众的IQueryable< MyDTO>获取(字符串ID)
{
  //一些code在这里
}

由于从可查询属性明显,该控制器始终,如果有时间返回10条记录超过10 MyDTO的

我如何能找出10条已全部归还或记录已经被ODATA查询选项过滤掉?


解决方案

 公开的IQueryable< MyDTO>获取(字符串ID,ODataQueryOptions< MyDTO> queryOptions)
    {
        IQueryable的< MyDTO> allMyDTOs = GetMyDTOs(ID);
        ODataQuerySettings设置=新ODataQuerySettings(){每页= 10};
        IQueryable的< MyDTO> appliedMyDTOs = queryOptions.ApplyTo(allMyDTOs,设置)为IQueryable的< MyDTO取代;
        返回appliedMyDTOs;
    }

下面是一些样品。

<一个href=\"http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options\" rel=\"nofollow\">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options

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?

解决方案

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

这篇关于如何找出哪些记录由Queryable已经被过滤掉的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆