Is there a way to do what this code did in EF Core RC 2?
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
Is there a way to do what this code did in EF Core RC 2?
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
There is no convention for this as of EF RC2 build. This is from EF Core team:
Now if you want to revert back to the RC1 naming conventions for tables, you have 3 ways to go with:
1. Choosing Singular Names for DbSet Properties:
One way is to singularize your DbSet property names (which I don't like). Say for example you have a Book entity and you want to map to a Book table:
2. Using ToTable() Fluent API:
You can of course always use fluent API to override any convention in place and dictate the table name to whatever you want:
3. Writing a Custom Convention:
Just because EF Core RC2 does not have a convention for this, it doesn't mean we can't write our own. To do so, first we need to create an extension method on
ModelBuilder
object:And then we simply call it from the OnModelCreating method on our DbContext object:
On Closing:
I don't like plural table names and I like the last option better than the others and went with that. That said, it's my personal opinion and other developers might find any of these 3 ways more favorable than the others and choose to go with that :)
The EF Core version doesn't seem to support
entity.DisplayName
. This is a working alternative:In Entity Framework NET core v2 you can choose to pluralize or singularize
DbSets
andCollections
with a hook.See this answer for more information: https://stackoverflow.com/a/47410837/869033