How do I toggle this convention PluralizingTableNameConvention
for only a single table/DbSet? As far as I can tell, I can only do this to all the DbSets
for a given DbContext
If you have only one entity which is mapped to a table that is not pluralizeed then you can remove the PluralizingTableNameConvention
and manually configure the table name of the entity.
public class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Item>().ToTable("Items");
}
}
Or if it is the otherway around
public class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Item>().ToTable("Item");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With