我正在尝试将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);