Search code examples
entity-frameworkentity-framework-4entity-framework-4.1code-first

Entity Framework | Code First - Get Name Of Created Table


Is it possible? I know I can get the name, when I've specified the TableAttribute, but it should be possible even so, when I let the framework manage the name.

Thanks in advance.


Solution

  • If you don't use TableAttribute or fluent api to define the table name, the name will be inferred from the name of DbSet property in the context. The only thing which can modify the name in such case is pluralization convention which is used by default.

    So if you have:

    public class Context : DbContext
    {
        public DbSet<User> Users { get; set; }
    }
    

    The table should be named Users.