In my MVC5 project, I have exteneded the IdentityUser class in my DbContext with the following implementation:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>() .ToTable("Users"); modelBuilder.Entity<ApplicationUser>() .ToTable("Users"); } } Using an ApplicationUser class:
public class ApplicationUser : IdentityUser { public string EmailAddress { get; set; } public string Name { get; set; } public DateTime JoinDate { get; set; } public string ConfirmationToken { get; set; } public bool EmailIsConfirmed { get; set; } } However, whenever I try to do the same thing and extend the IdentityRole class it is not working. If I simply create an ApplicationRole class that inherits from IdentityRole (and change all instances of IdentityRole in my MVC project to ApplicationRole), then no roles are returned from the database. For example, using the following
RoleManager<ApplicationRole> RoleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(new ApplicationDbContext()));
yields a result count of 0 when I call RoleManager.Roles.
Has anyone done this yet and could provide some guidance?
UPDATE I had forgotten to change my DB Seed method to use my new ApplicationRole - it was still using IdentityRole. After doing so, I couldn't apply an update to my database because I kept getting a DBValidation error. After adapting some of the code from this post, I was able to get everything working by overriding the ValidateEntity method of the DbContext