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
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 (the default) to allow unlimited depth.
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 (the default) to allow unlimited rows.
Set to 0 to not return any rows (but why would you do that?).
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.
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
OnActionExecuted(ActionExecutedContext)
Extract the IQueryable from the context, apply the query, and execute it.
public override void OnActionExecuted(ActionExecutedContext context)
Parameters
contextActionExecutedContext
OnActionExecuting(ActionExecutingContext)
Check if context.ModelState is valid
public override void OnActionExecuting(ActionExecutingContext context)
Parameters
contextActionExecutingContext