EnableQueryAttribute Class

 

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 https://go.microsoft.com/fwlink/?LinkId=279712.

Namespace:   System.Web.Http.OData
Assembly:  System.Web.Http.OData (in System.Web.Http.OData.dll)

Inheritance Hierarchy

System.Object
  System.Attribute
    System.Web.Http.Filters.FilterAttribute
      System.Web.Http.Filters.ActionFilterAttribute
        System.Web.Http.OData.EnableQueryAttribute
          System.Web.Http.QueryableAttribute

Syntax

[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method, 
    Inherited = true, AllowMultiple = false)]
public class EnableQueryAttribute : ActionFilterAttribute
[AttributeUsageAttribute(AttributeTargets::Class | AttributeTargets::Method, 
    Inherited = true, AllowMultiple = false)]
public ref class EnableQueryAttribute : ActionFilterAttribute
[<AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method,
    Inherited = true, AllowMultiple = false)>]
type EnableQueryAttribute = 
    class
        inherit ActionFilterAttribute
    end
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method,
    Inherited := True, AllowMultiple := False)>
Public Class EnableQueryAttribute
    Inherits ActionFilterAttribute

Constructors

Name Description
System_CAPS_pubmethod EnableQueryAttribute()

Enables a controller action to support OData query parameters.

Properties

Name Description
System_CAPS_pubproperty AllowedArithmeticOperators

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

System_CAPS_pubproperty AllowedFunctions

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

[list type="definition"] [item] [term]String related[/term] [description]substringof, endswith, startswith, length, indexof, substring, tolower, toupper, trim, concat e.g. ~/Customers?$filter=length(CompanyName) eq 19[/description] [/item] [item] [term]DateTime related[/term] [description]year, years, month, months, day, days, hour, hours, minute, minutes, second, seconds e.g. ~/Employees?$filter=year(BirthDate) eq 1971[/description] [/item] [item] [term]Math related[/term] [description]round, floor, ceiling[/description] [/item] [item] [term]Type related[/term] [description]isof, cast[/description] [/item] [item] [term]Collection related[/term] [description]any, all[/description] [/item] [/list]

System_CAPS_pubproperty 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'.

System_CAPS_pubproperty AllowedOrderByProperties

Gets or sets a string with comma seperated 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.

System_CAPS_pubproperty AllowedQueryOptions

Gets or sets the query parameters that are allowed in queries. The default is all query options, including $filter, $skip, $top, $orderby, $expand, $select, $inlineCount, $format and $skiptoken.

System_CAPS_pubproperty AllowMultiple

Gets a value that indicates whether multiple filters are allowed.(Inherited from FilterAttribute.)

System_CAPS_pubproperty EnableConstantParameterization

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

System_CAPS_pubproperty EnsureStableOrdering

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

System_CAPS_pubproperty HandleNullPropagation

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

System_CAPS_pubproperty 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. The default value is 1.

System_CAPS_pubproperty 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.

System_CAPS_pubproperty MaxNodeCount

Gets or sets the maximum number of nodes inside the $filter syntax tree. The default value is 100.

System_CAPS_pubproperty MaxOrderByNodeCount

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

System_CAPS_pubproperty MaxSkip

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

System_CAPS_pubproperty MaxTop

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

System_CAPS_pubproperty PageSize

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

System_CAPS_pubproperty TypeId

(Inherited from Attribute.)

Methods

Name Description
System_CAPS_pubmethod 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.

System_CAPS_pubmethod ApplyQuery(Object, ODataQueryOptions)

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

System_CAPS_pubmethod Equals(Object)

(Inherited from Attribute.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethod 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.

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod IsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethod Match(Object)

(Inherited from Attribute.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethod 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.(Overrides ActionFilterAttribute.OnActionExecuted(HttpActionExecutedContext).)

System_CAPS_pubmethod OnActionExecutedAsync(HttpActionExecutedContext, CancellationToken)

(Inherited from ActionFilterAttribute.)

System_CAPS_pubmethod OnActionExecuting(HttpActionContext)

Occurs before the action method is invoked.(Inherited from ActionFilterAttribute.)

System_CAPS_pubmethod OnActionExecutingAsync(HttpActionContext, CancellationToken)

(Inherited from ActionFilterAttribute.)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

System_CAPS_pubmethod 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.

Explicit Interface Implementations

Name Description
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod IActionFilter.ExecuteActionFilterAsync(HttpActionContext, CancellationToken, Func<Task<HttpResponseMessage>>)

Executes the filter action asynchronously.(Inherited from ActionFilterAttribute.)

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

System.Web.Http.OData Namespace

Return to top