AddEntityFrameworkStores can only be called with a role that derives from IdentityRole in .NET Core 2.0

I changed the project from .NET Core 1.1 to 2.0, but I get an error from Identity when it tries to add stores:

services.AddIdentity<ApplicationUser, IdentityRole<long>>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); 

Error thrown:

AddEntityFrameworkStores can only be called with a role that derives from IdentityRole

These are my classes:

 public class ApplicationUser : IdentityUser<long> { } public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long> { public ApplicationDbContext(DbContextOptions options) : base(options) { } } 

Can anybody help me?

+10
asp.net-core-mvc .net-core asp.net-identity
source share
2 answers

Once upon a time I asked this question, but here's how I deal with it now:

Startup.cs

 services.AddIdentity<User, Role>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddScoped<RoleManager<Role>>(); 

Entites:

 public class User : IdentityUser<int> { } public class Role : IdentityRole<int> { } 
0
source share

In the same issue, you can see: https://github.com/aspnet/Identity/issues/1364

+3
source share

All Articles