Why do I get this error: "Using the generic type 'IdentityUserRole' requires 1 type arguments" when trying to rename the tables created using Identity. Please see my code below:
protected override void OnModelCreating(ModelBuilder modelBuilder){
base.OnModelCreating(modelBuilder);
//AspNetUsers -> User
modelBuilder.Entity<AppUser>()
.ToTable("User");
//AspNetRoles -> Role
modelBuilder.Entity<IdentityRole>()
.ToTable("Role");
//AspNetUserRoles -> UserRole
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole");
//AspNetUserClaims -> UserClaim
modelBuilder.Entity<IdentityUserClaim>()
.ToTable("UserClaim");
//AspNetUserLogins -> UserLogin
modelBuilder.Entity<IdentityUserLogin>()
.ToTable("UserLogin");
}
I do not get any error on the Entity AppUser and Entity IdentityRole but on the rest, I get the error. Please see image below:
The problem is that IdentityUserRole, IdentityuserClaim and IdentityuserLogin are generic classes too. Because the key for this table is specified by the generic type.
This is from the documentation
IdentityUserLogin Class
And the implementation
Github implementation
So you have to do the following for example:
modelBuilder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
I hope this help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With