Entity Framework Removing Conventions


Example

You can remove any of the conventions defined in the System.Data.Entity.ModelConfiguration.Conventions namespace, by overriding OnModelCreating method.

The following example removes PluralizingTableNameConvention.

public class EshopContext : DbContext 
{ 
    public DbSet<Product> Products { set; get; }
    . . . 
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
    } 
}

By default EF will create DB table with entity class name suffixed by 's'. In this example, Code First is configured to ignore PluralizingTableName convention so, instead of dbo.Products table dbo.Product table will be created.