拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 迁移问题AspNetCoreAPI

迁移问题AspNetCoreAPI

白鹭 - 2022-02-02 1975 0 0

我正在开发一个项目,在该项目中我使用代码优先方法来添加现有物体的迁移。我正面临影像中显示的以下相关问题。

迁移问题 AspNetCore API

这是我的 dbContext 类

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

    }

这是 License User 和 LicenseUserRole 类

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。

uj5u.com热心网友回复:

对于这个问题,我可以在注册错误时重现它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...
}
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *