Ibanez1408
Ibanez1408

Reputation: 5078

Using the generic type 'IdentityUserRole<TKey>' requires 1 type arguments

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:

enter image description here

Upvotes: 5

Views: 2829

Answers (1)

Darem
Darem

Reputation: 1749

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.

Upvotes: 10

Related Questions