Skip to content

Commit 3c55f7d

Browse files
committed
Enable custom naming for table names
1 parent e158dc3 commit 3c55f7d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

application/shared-kernel/SharedKernel/EntityFramework/SharedKernelDbContext.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3030
// Set pluralized table names for all aggregates
3131
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
3232
{
33-
var tableName = entityType.GetTableName()!.Pluralize();
34-
entityType.SetTableName(tableName);
33+
var tableNameAnnotation = entityType.GetAnnotations().FirstOrDefault(a => a.Name == "Relational:TableName");
34+
if (tableNameAnnotation?.Value is not null)
35+
{
36+
entityType.SetTableName(tableNameAnnotation.Value.ToString());
37+
}
38+
else
39+
{
40+
var tableName = entityType.GetTableName()!.Pluralize();
41+
entityType.SetTableName(tableName);
42+
}
3543
}
3644

3745
// Ensures that all enum properties are stored as strings in the database.

0 commit comments

Comments
 (0)