无法为'IdentityRoleClaim <int>'创建DbSet

时间:2017-03-15 22:52:51

标签: c# asp.net-identity asp.net-core-mvc

我正在尝试为已经创建的数据库创建一个自定义标识,它适用于登录但没有角色的用户,但是有角色的用户会显示此错误。

  

无法为“IdentityRoleClaim”创建DbSet,因为此类型   未包含在上下文的模型中

Startup.cs

var server = {hostname: "hummingbird", uptime: "90 days, 23 hours, 12 minutes ...}

自定义标识类

 services.AddIdentity<ApplicationIdentityUser, CustomRole>()
            .AddUserStore<CustomUserStore<ApplicationIdentityUser>>()
            .AddUserManager<CustomUserManager<ApplicationIdentityUser>>()
              .AddRoleStore<CustomRoleStore<ApplicationIdentityUser>>()
              .AddRoleManager<CustomRoleManager>()

            .AddEntityFrameworkStores<AhUserContext, int>()
            .AddDefaultTokenProviders();
        services.AddMvc()
          .AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
          .AddDataAnnotationsLocalization();


        //Add the custom Password Hasher
        services.AddScoped<PasswordHasher<ApplicationIdentityUser>, CustomPasswordHasher<ApplicationIdentityUser>>();
        services.AddScoped<IdentityRole<int>, CustomRole>();
        services.AddScoped<IdentityRoleClaim<int>, CustomIdentityRoleClaim>();
        services.AddScoped<SignInManager<ApplicationIdentityUser>, CustomSignInManager<ApplicationIdentityUser>>();
        services.AddScoped<IdentityUserClaim<int>, CustomIdentityUserClaim>();
        services.AddScoped<IdentityUserLogin<int>, CustomIdentityUserLogin>();
        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();

        services.AddOptions();
        services.Configure<AppSettings>(Configuration.GetSection("MicrosoftAzureStorage"));

        services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();

1 个答案:

答案 0 :(得分:1)

变化:

public class CustomRoleStore<ApplicationIdentityUser> : RoleStore<CustomRole, AhUserContext, int>

public class CustomRoleStore<ApplicationIdentityUser> : RoleStore<CustomRole, AhUserContext, int, CustomIdentityUserRole, CustomIdentityRoleClaim >

我有同样的问题。因为我既有自定义UserManager又有RoleManager,所以两者都必须正确地传播继承链才能使它全部工作。