Skip to content

MultitenantIdentityDbContext Roles ConfigurationΒ #1074

@goforebroke

Description

@goforebroke

Andrew,

I would like to configure the asp_net_roles table as not multitenant. I have used the IsNotMultitenant() method in my ApplicationRole configuration, but the table still gets created with the tenant_id column. The docs say all entities will be configured as multitenant by default. The asp_net_users table is created without the tenant_id, but the roles table is not. Is it possible to make the roles table not multitenant?

    public sealed class ApplicationRoleConfiguration : IEntityTypeConfiguration<ApplicationRole>
    {
        public void Configure(EntityTypeBuilder<ApplicationRole> builder)
        {
            builder.IsNotMultiTenant();
        }
    }
public sealed class IdentityApiDbContext : MultiTenantIdentityDbContext<ApplicationUser, ApplicationRole, string>
{

    public IdentityApiDbContext(IMultiTenantContextAccessor<AppTenantInfo> multiTenantContextAccessor, 
        DbContextOptions<IdentityApiDbContext> options): base(multiTenantContextAccessor, options)
    {

    }

    public IdentityApiDbContext(IMultiTenantContextAccessor<AppTenantInfo> multiTenantContextAccessor) : base(multiTenantContextAccessor)
    {

    }


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.ApplyConfiguration(new ApplicationUserConfiguration());
        modelBuilder.ApplyConfiguration(new ApplicationRoleConfiguration());

        // Preserve snake case naming convention
        foreach (var entityType in modelBuilder.Model.GetEntityTypes())
        {
            // Set the table name to be the same as the entity type name
            entityType.SetTableName(entityType.GetTableName().ToSnakeCase());

            foreach (var property in entityType.GetProperties())
            {
                property.SetColumnName(property.Name.ToSnakeCase());
            }
        }

    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions