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.
29 lines
953 B
29 lines
953 B
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));
|
|
}
|
|
}
|
|
}
|
|
} |