Table of Contents

Class BreezeQueryFilterAttribute

Namespace
Breeze.AspNetCore
Assembly
Breeze.AspNetCore.NetCore.dll

Attribute to apply the request's query string to the returned IQueryable and execute it synchronously.

public class BreezeQueryFilterAttribute : ActionFilterAttribute, IActionFilter, IAsyncActionFilter, IResultFilter, IAsyncResultFilter, IOrderedFilter, IFilterMetadata
Inheritance
BreezeQueryFilterAttribute
Implements
Inherited Members

Remarks

Put [BreezeQueryFilter] 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 [BreezeAsyncQueryFilter] because of https://github.com/dotnet/efcore/issues/18221

Register one globally (options.Filters.Add(new BreezeQueryFilterAttribute { MaxTake = 1000, MaxDepth = 2 })) to bound every query action, and put one on a controller or action to change the limits there. The filter nearest the action runs the query; a limit it leaves unset comes from the nearest Breeze query filter at a wider scope (see MaxTake).

See https://breeze.github.io/doc-net/webapi-controller-core#breezequeryfilterattribute

Properties

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

int

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

int

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 [BreezeQueryFilter] 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

bool

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

OnActionExecuted(ActionExecutedContext)

Extract the IQueryable from the context, apply the query, and execute it.

public override void OnActionExecuted(ActionExecutedContext context)

Parameters

context ActionExecutedContext

OnActionExecuting(ActionExecutingContext)

Check if context.ModelState is valid

public override void OnActionExecuting(ActionExecutingContext context)

Parameters

context ActionExecutingContext