New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core: Table names now taken from DbSet names (starting in RC2) #167

rowanmiller opened this Issue Apr 5, 2016 · 1 comment


None yet
2 participants

rowanmiller commented Apr 5, 2016

In past pre-release of EF Core, the table name for an entity was the same as the entity class name. In RC2 we now use the name of the DbSet property. If no DbSet property is defined for the given entity type, then the entity class name is used.

For example, given the following model, in RC1 the table name for Blog would have been dbo.Blog, in RC2 it will be dbo.Blogs.

public class Blogging : DbContext
    public DbSet<Blog> Blogs { get; set; }


public class Blog
    public int BlogId { get; set; }
    public string Url { get; set; }

Impact on existing apps

If you upgrade an app from RC1 to RC2, you have several options:

  • If you are generating the database from the model, you can scaffold a new migration to apply the naming changes (or drop and recreate the database if you are using EnsureCreated() rather than migrations).
  • Manually specify table names to match what was chosen in RC1. This can be done in OnModelCreating or with the [Table] attribute. See the docs for more info.
  • Use the code from the following section to bulk configure table names to match what was chosen in RC1.

Reverting to RC1 naming

If you want to revert back to the RC1 naming conventions for tables, add the following code to the start of the OnModelCreating method on your context (requires a using statement for Microsoft.EntityFrameworkCore.Metadata.Internal).

foreach (var entity in modelBuilder.Model.GetEntityTypes())
    entity.Relational().TableName = entity.DisplayName();

@rowanmiller rowanmiller added this to the 1.0.0-rc2 milestone Apr 5, 2016

@aspnet aspnet locked and limited conversation to collaborators Apr 5, 2016


This comment has been minimized.

Show comment
Hide comment

divega Apr 6, 2016


You can use aspnet/EntityFrameworkCore#4996 for discussions.


divega commented Apr 6, 2016

You can use aspnet/EntityFrameworkCore#4996 for discussions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.