.Net核心扩展IdentityUserRole以包括实例/公司,并扩展RoleManger以获取实例

时间:2019-10-22 20:21:44

标签: asp.net-core asp.net-core-identity asp.net-core-3.0

我正在尝试将IdentityUserRole扩展为包括实例/公司,并扩展RoleManger以在asp.net Core 3.0中获取实例。

public class UserRole : IdentityUserRole<Guid>
{
    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
    public virtual Instance Instance { get; set; }

}


        builder.Entity<UserRole>(userRole =>
        {
            userRole.HasKey(ur => new { ur.UserId, ur.RoleId });

            userRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();

            userRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();

        });

如何扩展UserManager以使用InstanceId以及User和RoleName?

_userManager.AddToRoleAsync(user, "Admin", instanceId);

0 个答案:

没有答案