chore: Methode zur Aktualisierung von Spaltennamen gemäß Digital Data GmbH-Konventionen entwickeln
- Methode erstellt, um Spaltennamen in Entity Framework an die Benennungsstandards der Digital Data GmbH anzupassen. - Entity Framework-Migrationen aktualisiert, um diese Änderungen widerzuspiegeln.
This commit is contained in:
@@ -3,6 +3,10 @@ using DAL.Models.Entities;
|
||||
using HRD.WebApi.DAL;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
@@ -201,7 +205,33 @@ namespace DAL
|
||||
entity.ToTable("TBSTF_WEB_APP_EMPLOYEE_INFO", "dbo");
|
||||
});
|
||||
|
||||
Configure4DDNaming(modelBuilder.Model.GetEntityTypes().ToArray());
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
public static void Configure4DDNaming(params IMutableEntityType[] entityTypes)
|
||||
{
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
// Configure column names
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
var columnName = ToSnakeCase(property.Name);
|
||||
property.SetColumnName(columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string ToSnakeCase(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
var startUnderscores = System.Text.RegularExpressions.Regex.Match(input, @"^_+");
|
||||
return startUnderscores + System.Text.RegularExpressions.Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user