I try to edit my application to work with multitenant. I chose shared database separate schema approach. I use EF code first in my app. I've added Tenant Name as a scheme name) for the Table in EntityTypeConfiguration:
public UserConfiguration()
{
var currentTenant = Program.GetCurrentTenantId();
ToTable("User", currentTenant);
this.HasKey(u => u.Id);
this.Property(u => u.UserName).HasMaxLength(100).IsRequired();
this.Property(u => u.Email).HasMaxLength(100);
}
And simple code for getting tenantId:
public static string GetCurrentTenantId()
{
Console.WriteLine("tenant id:");
var id = Console.ReadLine();
return id;
}
How can I create tables for new scheme automatically? Before that I did it manually with migration(add-migration -> update-database). What I expect to see:
- I enter "First Tenant" in the console
- All tables with scheme name "First Tenant" are created in my database