Edit

Share via


Ignore query option

Applies To:# OData WebApi v7 for aspnet webapi supported Green circle with a checkmark inside it. OData AspNet WebApi V7# OData Webapi for Webapi supported Green circular checkmark icon to indicate a success. OData AspNet WebApi V6

In OData WebApi 5.7, we can ignore some query options when calling ODataQueryOption ApplyTo method, this is helpful when your OData service is integrate with other service that may already applied those query options.

Customize

public class MyEnableQueryAttribute : EnableQueryAttribute
{
    public override IQueryable ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
    {
       // Don't apply Skip and Top.
       var ignoreQueryOptions = AllowedQueryOptions.Skip | AllowedQueryOptions.Top;
       return queryOptions.ApplyTo(queryable, ignoreQueryOptions);
    }
}

Controller

[MyEnableQuery]
public IHttpActionResult Get()
{
    return Ok(_products);
}

Result

Then your queryOption won't apply Top and Skip.