using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using System; using System.Globalization; using System.Text.RegularExpressions; namespace Infrastructure.Data { public static class ModelBuilderExtensions { public static void RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder) { if (modelBuilder == null) { throw new ArgumentNullException(nameof(modelBuilder)); } foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes()) { var tableName = entity.DisplayName(); var match = Regex.Match(tableName, "<(.+)>"); if (match.Success) { tableName = match.Groups[1].Value; } entity.SetTableName(tableName.ToLower(CultureInfo.CurrentCulture)); } } } }