Avoid 'Discriminator' with AspNetUsers, AspNetRoles, & AspNetUserRoles

前端 未结 1 1950
名媛妹妹
名媛妹妹 2020-12-03 13:07

I am extending IdentityUser, IdentityUserRole, and IdentityRole like this:

public class ApplicationUser : IdentityUser         


        
相关标签:
1条回答
  • 2020-12-03 13:33

    Your context is inheriting IdentityDbContext<TUser> which in turn inherits IdentityDbContext<TUser, IdentityRole, string>. TUser in this case is your ApplicationUser, but the role type is IdentityRole.

    Thus the base class fluent configuration registers IdentityRole as entity. When you register the derived ApplicationRole as entity, EF Core treats that as TPH (Table Per Hierarchy) Inheritance Strategy which is implemented with single table having Discriminator column.

    To fix the issue, simply use the proper base generic IdentityDbContext. Since you also have a custom IdentityUserRole derived type, you should use the one with all generic type arguments - IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken>:

    public class SmartAccountingSetUpContext : IdentityDbContext
    <
        ApplicationUser, // TUser
        ApplicationRole, // TRole
        string, // TKey
        IdentityUserClaim<string>, // TUserClaim
        ApplicationIdentityUserRole, // TUserRole,
        IdentityUserLogin<stringy>, // TUserLogin
        IdentityRoleClaim<string>, // TRoleClaim
        IdentityUserToken<string> // TUserToken
    >
    {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题