Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 894
Ibanez1408 Avatar asked Jan 27 '23 20:01

Ibanez1408


1 Answers

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.

like image 200
Darem Avatar answered Feb 02 '23 00:02

Darem