迁移问题 AspNetCore API

Migration Issue AspNetCore API

我正在开展一个项目,在该项目中我使用代码优先方法来添加现有实体的迁移。我遇到了图中所示的以下相关问题。

这是我的 dbContext class

 public class LicenseDbContext: IdentityDbContext<LicenseUser, LicenseUserRole, long>
    {
        public LicenseDbContext(
           DbContextOptions<LicenseDbContext> options
           ) : base(options)
        {
        }

    }

这是 License User 和 LicenseUserRole classes

public class LicenseUser : IdentityUser<long>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public ApplicationRoleEnum UserRole { get; set; }
    }
    
 public class LicenseUserRole : IdentityRole<long>
    {
        public LicenseUserRole() : base()
        {
        }

        public LicenseUserRole(string roleName) : base(roleName)
        {

        }
    }

我使用的是 EF Core 5.0.9 版。虽然我只安装了 Core,但它总是说同时安装了 EF6 和 EFCore。

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: GenericArguments[1], 'Microsoft.AspNetCore.Identity.IdentityRole', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]' violates the constraint of type 'TRole'.

这个问题,我注册错了可以重现IdentityRole

请务必像下面这样注册您的服务:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<LicenseDbContext>(options =>
        options.UseSqlServer(
            Configuration.GetConnectionString("DefaultConnection")));

    services.AddIdentity<LicenseUser, LicenseUserRole>(options => options.SignIn.RequireConfirmedAccount = false)
        .AddEntityFrameworkStores<LicenseDbContext>();
    //other services...
}