How to implement Snake Case Naming Convention for MySql and PostreSql Providers? #6315
Replies: 3 comments
-
I have a design time factory approach I was trying out but still can't get it to fire to perform the snake casing: using Elsa.EntityFrameworkCore.Common.Abstractions;
using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Alterations;
using Elsa.EntityFrameworkCore.Modules.Identity;
using Elsa.EntityFrameworkCore.Modules.Labels;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Marques.EFCore.SnakeCase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace MyServer;
public class MySqlDesignTimeDbContextFactory<TDbContext> : DesignTimeDbContextFactoryBase<TDbContext> where TDbContext : DbContext
{
protected override void ConfigureBuilder(DbContextOptionsBuilder<TDbContext> builder, string connectionString)
{
builder.UseElsaMySql(typeof(DbContextOptionsBuilder).Assembly, connectionString);
builder.ReplaceService<IModelCustomizer, SnakeCaseModelCustomizer>();
}
}
public class SnakeCaseModelCustomizer(ModelCustomizerDependencies dependencies) : ModelCustomizer(dependencies)
{
public override void Customize(ModelBuilder modelBuilder, DbContext context)
{
base.Customize(modelBuilder, context);
modelBuilder.ToSnakeCase();
}
}
public class IdentityDbContextFactory : MySqlDesignTimeDbContextFactory<IdentityElsaDbContext>;
public class ManagementDbContextFactory : MySqlDesignTimeDbContextFactory<ManagementElsaDbContext>;
public class RuntimeDbContextFactory : MySqlDesignTimeDbContextFactory<RuntimeElsaDbContext>;
public class LabelsDbContextFactory : MySqlDesignTimeDbContextFactory<LabelsElsaDbContext>;
public class AlterationsDbContextFactories : MySqlDesignTimeDbContextFactory<AlterationsElsaDbContext>; |
Beta Was this translation helpful? Give feedback.
-
@Suchiman or @sfmskywalker any ideas? I only ask you because I see you both were the last to work in this area of the MySql package recently. I just can't seem to get a hold of these DbContext's so I can call |
Beta Was this translation helpful? Give feedback.
-
I opened #6337 requesting this be added as a configurable option on the EF core configuration so users have more flexibility in setting this up. |
Beta Was this translation helpful? Give feedback.
-
I'm using Elsa.EntityFrameworkCore.MySql but by default it creates all of the table names in lower case and spaced together with no underscore:
Typically MySQL uses snake case (i.e.
workflow_definitions
andworkflow_instances
and normally I import a nuget library like EfSnakeCase or Marques.EFCorev8.0.SnakeCase and then if I can just get access to Elsa'sDbContext
, I could do something like this:Is there an official or supported way to get Elsa's MySql provider to add an option for respecting the default naming conventions for the database you're using?
Beta Was this translation helpful? Give feedback.
All reactions