Menu

Entity Framework Core extensions remove pluralisation of table name

Since Entity Framework Core is fairly new and still under development most of the features that came out-of-the-box are not available. You will have to create extensions for these features. One of the items is remove pluralisation of table name.

Create a file called ModelBuilderExtensions.cs in your project. below is the code for the extension.

public static class ModelBuilderExtensions
{
  public static void RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder)
    {
    foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes())
    {
      entity.Relational().TableName = entity.DisplayName();
    }
  }
}

And in your DbContext file

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
   modelBuilder.RemovePluralizingTableNameConvention();
   .....
}

 

Leave a comment