You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Data/ModelBuilderExtensions.cs

24 lines
803 B

using System.Text.RegularExpressions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Infrastructure.Data
{
public static class ModelBuilderExtensions
{
public static void RemovePluralizingTableNameConvention(this ModelBuilder 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());
}
}
}
}