AutoQuery / AutoCrud Extra Options

We are ServiceStack-ifying an old NancyFX backend, and so far I’m LOVING the AutoCrud / ICrud feature. I have a few questions / suggestions.

  1. Would it be possible to add a new option to make dto / db class names singular (or plural) where appropriate for AutoCrud? I.E.: at the top of dtos.cs MakeSingular: True or something (there may be a way, I just haven’t found it in the docs yet).

A little background: I just took over this system - and the database schema naming is very inconsistent. SS has actually handled it VERY well, because we have table names like: Employee, client_note, plan_rates (capitalized, underscored, plural, and singular lol).

But if we could normalize everything to be singular in c#, that would be amazing.

  1. Digging through the docs, I don’t see a way to override any implemented ICrud type services for custom business logic. Is this a possibility? (similar to overriding / extending AutoQuery services).

Sorry for the long post. Thanks for all your hard work on ICrud - ServiceStack feels full circle now.

EDIT: Removed #2, now that I see how they are generated (via API), this would be difficult to spit out multiple files.

What’s an example of the customization you’re after, i.e. the table name, the current DTO names and the proposed names that you’re after?

How many tables are you wanting to customize? Can you just eject the generated models and customize them how you like?

Table Name: applications
Current Dto Names: CreateApplications, PatchApplications (types\Applications)
Proposed DTO Names: CreateApplication, PatchApplication, (types\Application)

It’s about 20-30 models that need to be singularized, and yes, ultimately I can just eject and customize if need be.

I’ve added customizable generation options in the new GenerateOperationsFilter where you can customize different aspects of AutoGen’s code generation, e.g. here’s an example of the different customization options available:

Plugins.Add(new AutoQueryFeature {
    MaxLimit = 1000,
    GenerateCrudServices = new GenerateCrudServices {
        AutoRegister = true,
        GenerateOperationsFilter = ctx => {
            if (ctx.TableName == "applications")
                ctx.DataModelName = "Application";
                ctx.RoutePathBase = "/apps";
                ctx.OperationNames = new Dictionary<string, string> {
                    [AutoCrudOperation.Create] = "CreateApp",
                    [AutoCrudOperation.Query] = "SearchApps",

Where it will use:

  • Application instead of Applications for the Data Model Name.
  • /apps instead of /applications for the Route’s Path
  • CreateApp instead of CreateApplications, SearchApps instead of QueryOperations

Other operations retain the default Query + DataModelName, e.g. DeleteApplication.

This change is available from v5.9.1 that’s now available on MyGet.

1 Like

Wow, that was fast, thank you @mythz!