Can someone please explain why my EnableQueryAttribute filter is not firing when the client query does not include the Count=True in their query? My entire dataset is returned.
public class EnableQueryWithDefaultPageSizeAttribute : EnableQueryAttribute
{
const int pageSizeDefault = 100;
public override IQueryable ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
{
int pagesize = pageSizeDefault;
var result = queryOptions.ApplyTo(queryable, new ODataQuerySettings { PageSize = pagesize });
return result;
}
}
The following query trigger the filter:
https://localhost:5001/api/teams?$count=true
This query doesn't trigger the filter:
https://localhost:5001/api/teams
The only way to solve it is to right now is to hard code my controller method with:
[EnableQuery(PageSize = 100)]
My gold is to have a global filter that sets the page size for any Odata API request. I've googled and read Microsoft documentation and still can't find a solution. Any help will be appreciated. I'm currently using .net core 6.0 and AspNetCoreOdata 8.0.6.
Have you tried deliberately setting the property in the constructor? This has the added benefit of still allowing you to override the default page size at each endpoint.
public class EnableQueryWithDefaultPageSizeAttribute : EnableQueryAttribute
{
public EnableQueryWithDefaultPageSizeAttribute()
{
this.PageSize = 100;
}
}
I think the issue in .Net 5/6 is the paging behaviour needs to be resolvable from the Edm, not from the individual Query, this is a breaking change from the .Net FX implementation when you couldmodify it on a per-request basis.