I am using Entity Framework Core 2.2 and all database table names are singular so I am overriding pluralise naming convention in OnModelCreating method
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
entityType.Relational().TableName = entityType.DisplayName();
}
}
However in some cases entity names are different to table names for example
[Table("AzureSchemaVersionExecutionExtract", Schema = "dbo")]
public class AzureDataExtract
{
public int Id { get; set; }
public DateTime DateApplied { get; set; }
}
When i run the project it complains as it cannot find the table AzureDataExtract so i added following code in OnModelCreating method and it works. I need to know is this the correct way to implement Data Annotations and Singular Naming Convention together
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
entityType.Relational().TableName = entityType.DisplayName();
}
modelBuilder.Entity<AzureDataExtract>().ToTable("AzureSchemaVersionExecutionExtract","dbo");
}