Strange Auto Query Issue

I am using Auto Query on a postgres database with different schemas on Servicestack 6.03 . My Configure.AutoQuery.cs looks like

public void Configure(IWebHostBuilder builder) => builder
        .ConfigureAppHost(appHost => {
            appHost.Plugins.Add(new AutoQueryFeature {
                MaxLimit = 1000,
                IncludeTotal = true,
                GenerateCrudServices = new GenerateCrudServices
                {
                    //IncludeService = op => !ignoreTables.Any(table => op.ReferencesAny(table)) &&
                    // !(op.IsCrudWrite()),

                    //IncludeType = type => !ignoreTables.Contains(type.Name),
                    ////when including app_user and putting app_users in types, get error
                    //AutoRegister = true,
                    CreateServices =
                    {
                        new CreateCrudServices(),
                        new CreateCrudServices{Schema = "Environment"},
                        new CreateCrudServices{Schema = "Governance"},
                        new CreateCrudServices{Schema = "HealthAndSafety"},
                        new CreateCrudServices{Schema = "Social"},
                        new CreateCrudServices{Schema = "TrainingAndDev"},
                        new CreateCrudServices{Schema = "Transformation"},
                        new CreateCrudServices{Schema = "Answers"},
                        new CreateCrudServices{Schema = "Configuration"},
                    }

                }
                //IncludeTotal = true,
            });
        });

I have the same table name under different schemas E.g. Question table. So I have a Governance.Question, Configuration.Question etc.

I am getting the following errors when running my service

      Initializing Application envisionapi took 6197.2544ms. 15 error(s) detected: [{"errorCode":"NotSupportedException","message":"Could not resolve type 'ConfigurationConfigurationConfigurationConfigurationConfigurationQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'GovernanceGovernanceGovernanceGovernanceGovernanceQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'HealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'ConfigurationConfigurationConfigurationConfigurationConfigurationQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'GovernanceGovernanceGovernanceGovernanceGovernanceQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'HealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'ConfigurationConfigurationConfigurationConfigurationConfigurationQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'GovernanceGovernanceGovernanceGovernanceGovernanceQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'HealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'ConfigurationConfigurationConfigurationConfigurationConfigurationQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'GovernanceGovernanceGovernanceGovernanceGovernanceQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'HealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'ConfigurationConfigurationConfigurationConfigurationConfigurationQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'GovernanceGovernanceGovernanceGovernanceGovernanceQuestion'","errors":[]},{"errorCode":"NotSupportedException","message":"Could not resolve type 'HealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyHealthAndSafetyQuestion'","errors":[]}]

However, the services still bind and I can use it, although the paths/ naming seems inconsistent.

For e.g. For the Auditors Schema, the services are called QueryAuditorsQuestions, PatchAuditorsQuestion etc, but for Configuration schema, it is just QueryQuestions etc…

Also, the path for QueryQuestions changed from configuration/questions to just questions after upgrading a minor SS version.

It’s not able to handle ambiguous types across multiple schemas. Only suggestions I can recommend trying is exporting the types into code-first Types so you can manually rename types so they’re all unique. You can use the [Alias] attribute to map a type of a different name to an RDBMS table.

Otherwise you can avoid conflicting types by splitting conflicting schemas into multiple AppHosts.

Would it not make sense to create unique aliasses automatically based on schema and table combined and to for e.g. make the path /schemaname/tablename.

Issue is, it used to work and it was resolving for e.g. configuration.question table to configuration/question, but it changed and we had to update our code.

Each schema definition runs independently that will be subject to conflicts with ambiguous classes, trying to resolve it in an opinionated way will likely result in breaking changes, cause more bugs and unwanted behavior.

Instead it’s better to generate the classes so you have the freedom to choose the class names and routes you want.

Or if you created multiple Apps for different schemas you could host them under a reverse proxy with a custom prefix to get your preferred routes. IMO this is preferred as you’re likely to continually run into conflicts trying to serve multiple DBs with ambiguous types in a single App, an App should really only be responsible for a single domain.

I am only using a single Postgres Database, just different schemas. How would I generate the classes for the types and the requests seperately. When I run https://localhost:5001/crud/all/csharp it does not seem to provide all my Types that exist in my database.

The schemas contain ambiguous Types which isn’t typical if they were all maintained in a single App.

Have a look at AutoGen specific options in AutoGen DTOs where you can save multiple *.cs files that are configured to look at different schemas.