Class BreezeAsyncQueryFilterAttribute
- Namespace
- Breeze.AspNetCore
- Assembly
- Breeze.AspNetCore.NetCore.dll
Attribute to apply the request's query string to the returned IQueryable and execute it asynchronously.
public class BreezeAsyncQueryFilterAttribute : ActionFilterAttribute, IActionFilter, IResultFilter, IAsyncResultFilter, IOrderedFilter, IAsyncActionFilter, IFilterMetadata
- Inheritance
-
BreezeAsyncQueryFilterAttribute
- Implements
- Inherited Members
Remarks
Put [BreezeAsyncQueryFilter] on a Controller class to apply Breeze query filtering and execution to each method that returns an IQueryable or IEnumerable.
You might want to use this class instead of [BreezeQueryFilter] to get the benefits of async tasks and cancellable queries.
The filter nearest the action runs the query; a limit it leaves unset comes from the nearest Breeze query filter at a wider scope, sync or async (see MaxTake).
See https://breeze.github.io/doc-net/webapi-controller-core#breezequeryfilterattribute
Properties
CancellationStatusCode
Status code when cancellation results are returned; default is 499 Client Closed Connection
public int CancellationStatusCode { get; set; }
Property Value
CatchCancellations
If true, OperationCanceledExceptions will be caught and an empty result will be returned.
public bool CatchCancellations { get; set; }
Property Value
MaxDepth
Sets max depth for Select and Expand clauses.
Set to 0 to disallow Selects and Expands requested by the client.
Set to -1 to allow unlimited depth.
Left unset, it comes from the nearest Breeze query filter at a wider scope (the controller's, or
one registered globally), and is unlimited if there is none. It reads -1 while unset.
Returns 400 Bad Request if MaxDepth is violated.
MaxDepth = 1 on IQueryable<Customer> will allow Expand = "Orders" but not "Orders.OrderDetails"
MaxDepth = 0 on IQueryable<Customer> will allow Select = "Name" but not Select = "Orders" or Expand = "Orders"
public int MaxDepth { get; set; }
Property Value
MaxTake
Sets max rows allowed; adds Take(MaxTake) to query if Take is unspecified or if Take > MaxTake.
Set to 100 to allow max of 100 rows on any query.
Set to -1 to allow unlimited rows.
Set to 0 to not return any rows (but why would you do that?).
Left unset, it comes from the nearest Breeze query filter at a wider scope (the controller's, or
one registered globally), and is unlimited if there is none. It reads -1 while unset.
NOTE: MaxTake does not affect Expand/Include subqueries, nor non-EF results (arrays, Lists, etc.)
public int MaxTake { get; set; }
Property Value
Remarks
MaxTake can be used to limit result size if the client accidently (or maliciously) does not apply any filtering.
MaxTake is not the same as adding a Take() clause in the controller method, because MaxTake is applied after any
Where and OrderBy provided in the request.
The filter nearest the action runs the query, so a wider filter's limits never reach it on
their own. Before, an attribute that left a limit unset meant "unlimited" even under a global
filter, and a bare [BreezeAsyncQueryFilter] lifted both limits; it now keeps the wider ones.
UsePost
If true and request is POST, then attempt to extract the Breeze query from the request body.
public bool UsePost { get; set; }
Property Value
Remarks
There is some overhead in extracting the request body, so UsePost should only be used on endpoints that are expected to have queries. If the request body has already been read (for example, due to model binding), it will need to be rewound before the filter can read it.
Methods
OnActionExecutionAsync(ActionExecutingContext, ActionExecutionDelegate)
Extract the IQueryable from the context, apply the query, and execute it.
public override Task OnActionExecutionAsync(ActionExecutingContext executingContext, ActionExecutionDelegate next)
Parameters
executingContextActionExecutingContextnextActionExecutionDelegate