InvalidOperationException: Cannot create a DbSet for 'Role' because this type is not included in the model for the context

Check that your AppDbContext is NOT inherited from DbContext but instead it should be inherited from IdentityDbContext<ApplicationUser>


Added this and it worked:

builder.Entity<IdentityUserRole<Guid>>().HasKey(p => new { p.UserId, p.RoleId });

The most common reasons for

Cannot create a DbSet for 'THE-MODEL' because this type is not included in the model for the context

are as follows

  1. The model name does not match with the table name in database
  2. EntityFramework cannot figure out required meta by convention and you have not overriden it.

in your case Role inherits IdentityRoleClaim and that was not configured and default convention required "Id" as key but i suppose it did not have that property so it had to be configured. It would also have worked if you created property in Role like Id => new{UserId,RoleId} which would by convention present Id as the key property to entity framework.