Autoquery GenerateCrudServices- Customize Query filter

I want to use GenerateCrudService with a multitenant db.
I have 2 main role: Admin and User.
Admin can see all the data in the table.
User can see only specific data based on a custom filter.
How I can customize the QueryRequest and customize the sql query?


Hi @Gianmaria,

Always best to include code related to the quest to provide more context where you can, but will do my best to point to related docs.

AutoQuery request DTOs can use the AutoFilter attribute that can be used to populate data on request from other sources using Eval. These use #Script methods that can be extended as well.

Alternatively the AutoPopulate attribute can be used to populate values on the DTO using #Script expressions as well.

If you provide a more concrete example, might be able to point to specific solution.

You can also use a GlobalRequestFilter to customize Request DTOs before they’re executed, if you need more customization than that you’ll need to create a custom AutoQuery implementation.

I used a custom AutoQuery implementation with my Service like this:

        var q = AutoQuery.CreateQuery(request, base.Request);
       [...] query customization          
       return AutoQuery.Execute(request, q);

Now I want to inject the same custom code in the Autogenerated service Request handler…

Thanks Gianmaria

Please read and follow the links of @layoric’s and my responses. He’s already provided links to the available customizations options. If the existing attributes are not sufficient, the way you customize AutoQuery implementation is to create a custom AutoQuery implementation.

You can also provide a custom base class to override the impl of all AutoQuery Services:

Thanks a lot.