Closed praiwann closed 3 years ago
Hi, @praiwann, column names should be generated using EF. In my tests https://github.com/win7user10/Laraue.EfCoreTriggers/blob/master/tests/Laraue.EfCoreTriggers.PostgreSqlTests/PostgreSqlGeneratingExpressionsTests.cs you can see that the property is correctly translated to snake case convention. How do you describe to EF, how will be named a column?
Hi @win7user10,
Unfortunately, I have use npgsql library and its snake case tranlsator NpgsqlSnakeCaseNameTranslator
We have implemented this to our core module and use them in many projects. BTW, from the test which you mention, it seems that we are working on different extension, in your case directly using EFCore.NamingConventions. So I will check that first and see if it is working as aspect then better try to switch to this extension for more EFCore compatible.
I will post the result here later. Thank you :)
Hi, @praiwann, the latest version of the library have the opportunity to customize any part of a code generation.
private class CustomPostgreSqlProvider : PostgreSqlProvider
{
public MySqlProvider(IModel model) : base(model)
{
}
protected override string GetColumnName(MemberInfo memberInfo)
{
return base.GetColumnName(memberInfo).ToSnakeCase();
}
}
var options = new DbContextOptionsBuilder<TestDbContext>()
.UseNpgsql("User ID=test;Password=test;Host=localhost;Port=5432;Database=test;")
.UseTriggers<CustomPostgreSqlProvider>()
.Options;
var dbContext = new TestDbContext(options);
It can be useful in your case.
Hi, @praiwann, the latest version of the library have the opportunity to customize any part of a code generation.
private class CustomPostgreSqlProvider : PostgreSqlProvider { public MySqlProvider(IModel model) : base(model) { } protected override string GetColumnName(MemberInfo memberInfo) { return base.GetColumnName(memberInfo).ToSnakeCase(); } }
var options = new DbContextOptionsBuilder<TestDbContext>() .UseNpgsql("User ID=test;Password=test;Host=localhost;Port=5432;Database=test;") .UseTriggers<CustomPostgreSqlProvider>() .Options; var dbContext = new TestDbContext(options);
It can be useful in your case.
@win7user10 Appreciate your works!!
Hi,
As mention in topic, can we configure the library or is there a way to use snake case as column name?
I have run migration and its seems to working fine but there is an error when trigger occur as I have use snake case column name in my database as default.
for example, if I have these column name in my DB
id, some_id, some_value
and in my code like so
It could not map column name because the trigger script generate the column as
Id, SomeId, SomeValue
which will translate to
id, someid, somevalue
BTW, I have use PostgreSQL as my database.