Database First approach and AutoQueryGrid

If we have been using the Database First approach to generate the AutoQueryFeature

Is there some way to use the new AutoQueryGrid with something like?

<AutoQueryGrid Model="Customer" Apis="Apis.AutoQuery<Customer>()" />

or is it restricted to the Code First Approach :sweat_smile:

Needing to supply the typed AutoQuery DTOs the component should use is a concession as we can’t do dynamic magic type inference in C# like we can do in JS.

Apis could be constructed with runtime types in its Apis(Type[] types) Constructor but you’re not going to be able to resolve those server generated types in WASM, might work in Blazor Server but we’re not going to support that use-case if it requires any architectural concessions.

You’re best off Exporting to code-first Types to utilize it, which basically applies to every “API aware” component in ServiceStack.Blazor Components.

Thank you
It is about time I switch to Code-first approach :grin:

1 Like

Trying the code first approach, similar to the Bookings example

public class MyobCustomer
    public int Id { get; set; }

[Route("/myobcustomers", "GET")]
[Route("/myobcustomers/{Id}", "GET")]
public class QueryMyobCustomers  : QueryDb<MyobCustomer>
    public int? Id { get; set; }

I can compile the Blazor WASM project as it now understands QueryMyobCustomers

<AutoQueryGrid Model="MyobCustomer" Apis="Apis.AutoQuery<QueryMyobCustomers,CreateMyobCustomer,UpdateMyobCustomer,DeleteMyobCustomer>()" />

using AutoQuery

public void Configure(IWebHostBuilder builder) => builder

    .ConfigureAppHost(appHost =>
        appHost.Plugins.Add(new AutoQueryFeature
            MaxLimit = 1000,
            IncludeTotal = true

but I can see that my CRUD Services are NOT generated (looking at metadata or admin-ui)

I sort of have to explicitly generate the Services using GenerateCrudServices to have them

public void Configure(IWebHostBuilder builder) => builder

    .ConfigureAppHost(appHost =>
        appHost.Plugins.Add(new AutoQueryFeature
           MaxLimit = 1000,
           IncludeTotal = true,
           GenerateCrudServices = new GenerateCrudServices
               CreateServices = {
                       new CreateCrudServices() { Schema = "public" },
                       new CreateCrudServices() { Schema = "dbo" },

We have the services

and in that case it is working but that does not make sense (I am reversing to the Database first approach) and the declaration in the Models of QueryMyobCustomers is only helping Blazor to find what it needs, but not helping to generate the CRUD services…

Am I missing something to do with the Schema to have my CRUD services generated?
Note: using PostgreSQL

Not sure, they should be discovered. Did you add the AutoQuery DTOs along side the Bookings AutoQuery DTOs in the template? Did the Bookings DTOs stop appearing in the /metadata page as well?

I added back the Bookings DTOs, running locally and using Sqlite
and nothing in the /metadata
Sorry, there must be something wrong with my project. Will restart from the beginning :sweat_smile:

Rebuilding the project from scratch using new (instead of getting the code from Github) everything is now working correctly.

1 Like

If found this issue.
If we remove the Hello service code from the MyServices.cs class in the MyApp.ServiceInterface project, the class is empty and then the AutoQuery CRUD Services do not get generated! If you add back the Hello service code, then the CRUD Services are again generated.

I’m assuming it’s an issue with assembly resolution then, is your MyServices class still used in the AppHost constructor and does it still have DTOs in the ServiceModel project?

Yes, that’s my point
If you start from your Blazor template

We have the Hello + Todo + Booking/Coupon CRUD services generated

If I comment out the Hello and Todo Services without changing anything else, the CRUD services from the Booking/Coupon DTOs stop being generated.

then, the Booking/Coupon CRUD services are NOT generated anymore

If you’ve removed all Services? it won’t be able to discover where your App’s service models are located.

Should not these ones be found?

If I want to have all my services as declarative Autoquery services

I can declare a dummy service as a work around, fair enough, but it took me ages to find out why my declarative services were not generated :sweat_smile:

It can only find them from the AppHost constructor Assembly which looks at the ServiceInterface Assembly which would need to have existing Services and DTOs in ServiceModel in order to be able to scan it as well.