Share via


EnableQueryAttribute Class

Definition

This class defines an attribute that can be applied to an action to enable querying using the OData query syntax. To avoid processing unexpected or malicious queries, use the validation settings on EnableQueryAttribute to validate incoming queries. For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public class EnableQueryAttribute : System.Web.Http.Filters.ActionFilterAttribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public class EnableQueryAttribute : Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)>]
type EnableQueryAttribute = class
    inherit ActionFilterAttribute
Public Class EnableQueryAttribute
Inherits ActionFilterAttribute
Inheritance
System.Web.Http.Filters.ActionFilterAttribute
EnableQueryAttribute
Inheritance
EnableQueryAttribute
Attributes

Constructors

EnableQueryAttribute()

Enables a controller action to support OData query parameters.

Properties

AllowedArithmeticOperators

Gets or sets a value that represents a list of allowed arithmetic operators including 'add', 'sub', 'mul', 'div', 'mod'.

AllowedFunctions

Gets or sets a value that represents a list of allowed functions used in the $filter query. Supported functions include the following:

AllowedLogicalOperators

Gets or sets a value that represents a list of allowed logical Operators such as 'eq', 'ne', 'gt', 'ge', 'lt', 'le', 'and', 'or', 'not'.

AllowedOrderByProperties

Gets or sets a string with comma separated list of property names. The queryable result can only be ordered by those properties defined in this list.

Note, by default this string is null, which means it can be ordered by any property.

For example, setting this value to null or empty string means that we allow ordering the queryable result by any properties. Setting this value to "Name" means we only allow queryable result to be ordered by Name property.

AllowedQueryOptions

Gets or sets the query parameters that are allowed in queries.

EnableConstantParameterization

Gets or sets a value indicating whether constants should be parameterized. Parameterizing constants would result in better performance with Entity framework.

EnableCorrelatedSubqueryBuffering

Gets or sets a value indicating whether queries with expanded navigations should be formulated to encourage correlated subquery results to be buffered. Buffering correlated subquery results can reduce the number of queries from N + 1 to 2 by buffering results from the subquery.

EnsureStableOrdering

Gets or sets a value indicating whether query composition should alter the original query when necessary to ensure a stable sort order.

HandleNullPropagation

Gets or sets a value indicating how null propagation should be handled during query composition.

HandleReferenceNavigationPropertyExpandFilter

Honor $filter inside $expand of non-collection navigation property. The expanded property is only populated when the filter evaluates to true. This setting is false by default.

MaxAnyAllExpressionDepth

Gets or sets the maximum depth of the Any or All elements nested inside the query. This limit helps prevent Denial of Service attacks.

MaxExpansionDepth

Gets or sets the max expansion depth for the $expand query option. To disable the maximum expansion depth check, set this property to 0.

MaxNodeCount

Gets or sets the maximum number of nodes inside the $filter syntax tree.

MaxOrderByNodeCount

Gets or sets the maximum number of expressions that can be present in the $orderby.

MaxSkip

Gets or sets the max value of $skip that a client can request.

MaxTop

Gets or sets the max value of $top that a client can request.

PageSize

Gets or sets the maximum number of query results to send back to clients.

Methods

ApplyQuery(IQueryable, ODataQueryOptions)

Applies the query to the given IQueryable based on incoming query from uri and query settings. By default, the implementation supports $top, $skip, $orderby and $filter. Override this method to perform additional query composition of the query.

ApplyQuery(Object, ODataQueryOptions)

Applies the query to the given entity based on incoming query from uri and query settings.

CreateErrorResponse(String, Exception)

Create an error response.

GetModel(Type, HttpRequest, ActionDescriptor)

Gets the EDM model for the given type and request.Override this method to customize the EDM model used for querying.

GetModel(Type, HttpRequestMessage, HttpActionDescriptor)

Gets the EDM model for the given type and request. Override this method to customize the EDM model used for querying.

OnActionExecuted(ActionExecutedContext)

Performs the query composition after action is executed. It first tries to retrieve the IQueryable from the returning response message. It then validates the query from uri based on the validation settings on EnableQueryAttribute. It finally applies the query appropriately, and reset it back on the response message.

OnActionExecuted(HttpActionExecutedContext)

Performs the query composition after action is executed. It first tries to retrieve the IQueryable from the returning response message. It then validates the query from uri based on the validation settings on EnableQueryAttribute. It finally applies the query appropriately, and reset it back on the response message.

OnActionExecuting(ActionExecutingContext)
ValidateQuery(HttpRequest, ODataQueryOptions)

Validates the OData query in the incoming request. By default, the implementation throws an exception if the query contains unsupported query parameters. Override this method to perform additional validation of the query.

ValidateQuery(HttpRequestMessage, ODataQueryOptions)

Validates the OData query in the incoming request. By default, the implementation throws an exception if the query contains unsupported query parameters. Override this method to perform additional validation of the query.

Applies to