0

How would you change the names of your tables using Entity Frameworks code first migrations.

The below code, creates my tables as :

RoleBindingModel, DivisionBindingModel etc. and that's not ideal.

How would you change the name to a custom table name? (Without changing your models name)

IdentityModels.cs

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public DbSet<RoleBindingModel> Role { get; set; }
        public DbSet<DivisionBindingModel> Division { get; set; }
        public DbSet<CategoryBindingModel> Category { get; set; }
        public DbSet<ProductBindingModel> Product { get; set; }


        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

Table names

1
  • you mean in runtime? Commented Jul 20, 2017 at 9:00

1 Answer 1

3

One way is by using DataAnnotations and the Table attribute.

using System.ComponentModel.DataAnnotations.Schema;    

[Table("Role")]
public class RoleBindingModel
{

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.