我正在開發一個專案,在該專案中我使用代碼優先方法來添加現有物體的遷移。我正面臨影像中顯示的以下相關問題。

這是我的 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熱心網友回復:
訪問 Microsoft.Extensions.Hosting 服務時出錯。在沒有應用程式服務提供商的情況下繼續。錯誤:GenericArguments[1], 'Microsoft.AspNetCore.Identity.IdentityRole', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]'違反了“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...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/394417.html
