1

I'm trying to servicify an existing RDBMS with C# AutoQuery, but getting this error:

  HResult=0x80131522
  Message=Type 'WebApplication1.ServiceModel.CreateCurrency' from assembly 'tmpCrudAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
  Source=ServiceStack
  StackTrace:
   at ServiceStack.ServiceStackHost.OnStartupException(Exception ex)
   at ServiceStack.ServiceStackHost.OnStartupException(Exception ex, String target, String method)
   at ServiceStack.ServiceStackHost.RunPostInitPlugin(Object instance)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at ServiceStack.ServiceStackHost.RunAfterPluginsLoaded(String specifiedContentType)
   at ServiceStack.ServiceStackHost.OnAfterInit()
   at ServiceStack.ServiceStackHost.Init()
   at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost)
   at Program.<Main>$(String[] args) in C:\Users\User\Desktop\Test\WebApplication1\WebApplication1\Program.cs:line 9

The target database is a mySQL database using BINARY(16) as primary key. Could this be the problem? When I target another mySQL database it's working like it should.

kaylum
  • 13,833
  • 2
  • 22
  • 31
Nesse
  • 373
  • 4
  • 14
  • 1
    Please be careful when selecting tags, so you don't just write one character and press enter to select the first tag. Because then you would select the C language tag instead of C#. – Some programmer dude May 16 '22 at 06:44
  • Show the code of `WebApplication1.ServiceModel.CreateCurrency`. – JHBonarius May 16 '22 at 06:51
  • I'd say it's likely the binary PK is the problem preventing the Table Data Model from being created which the API is unable to reference. – mythz May 16 '22 at 07:01
  • @mythz is this something I can fix? This is the documentation I've found => Shopware 6 works with UUIDv4 as primary keys instead of auto increments – Nesse May 16 '22 at 09:51
  • 1
    @Nesse AutoGen wont be able to infer a Guid from a binary column, but may work if you manually create the `Currency` table (which AutoGen should be able to detect + use) and use `Guid` for the PK then you'll need to create a [custom type converter](https://docs.servicestack.net/ormlite/type-converters) that maps a Guid to a binary column like [OracleGuidConverter.cs](https://github.com/ServiceStack/ServiceStack/blob/main/ServiceStack.OrmLite/src/ServiceStack.OrmLite.Oracle/Converters/OracleGuidConverter.cs#L36) – mythz May 16 '22 at 10:03
  • @mythz It does not seem to work. Could I exclude some tables instead? – Nesse May 17 '22 at 14:59
  • Yes, please see my answer for configuring AutoGen's code-gen behavior. – mythz May 18 '22 at 07:06

1 Answers1

1

You can control the tables that AutoGen generates the data models and APIs for when configuring the GenerateCrudServices instruction, e.g you can exclude a specific table with:

Plugins.Add(new AutoQueryFeature {
    GenerateCrudServices = new GenerateCrudServices {
        ExcludeTables = { "Currency" },
    }
});
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thx @mythz. When I try to use ExcludeTables It's not recognized within the GenerateCrudServices. => does not contain a definition for 'ExcludeTables'. Should I add an extension? – Nesse May 18 '22 at 07:35
  • @Nesse you'll need to upgrade – mythz May 18 '22 at 07:36
  • I've got it working using 'ExcludeTables'. Could it be that not every table is generated while excluding tables? – Nesse May 19 '22 at 06:41
  • @Nesse I don't know what this is referring to, if you have a new issue please ask a new question including all relevant context, behavior & error info. – mythz May 19 '22 at 07:08