Search code examples
c#asp.net-coreasp.net-core-mvcasp.net-identityasp.net-identity-3

Migrations is not detecting added property to ApplicationRole : IdentityRole


I am trying to add a property to the AspNetRoles table in ASP.NET Core Identity. I assumed the process would be the following:

  1. Create an ApplicationRole class that implements IdentityRole just like ApplicationUser implements IdentityUser.

  2. Add new property to ApplicationRole class.

  3. Replace IdentityRole with ApplicationRole throughout the application where necessary.

i.e.

services.AddIdentity<ApplicationUser, ApplicationRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();
  1. Add-Migration

During step 4 when adding the migration I end up with an empty migration file. Any idea why this isn't working like it works when adding additional properties to ApplicationUser and then adding migration?

I noticed ApplicationDbContext implements IdentityDbContext. How can I add my ApplicationRole to this. I believe this is my problem.


Solution

  • I don't know how is your ApplicationDbContext, but I think you have to put something like this in the declaration of it:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>