0

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:

  1. I enter "First Tenant" in the console
  2. All tables with scheme name "First Tenant" are created in my database
4
  • What I expect to see When/where/how? Commented Nov 12, 2016 at 11:18
  • when I enter new tenant name in the console and click enter I expect to see new tables with entered schema name in my database, for example: I enter 'tenant1' - > table dbo.tenant1.User(UserConfiguration for this table above, in my question) is created in database Commented Nov 12, 2016 at 12:05
  • Why should clicking enter create new tables? You seem to expect that we somehow know the code that is supposed to run after clicking enter. Well, maybe it's enough for you to know that ER creates a mapping model only once in an application's lifespan. Commented Nov 12, 2016 at 18:44
  • Why should clicking enter create new tables? because it is the technical task) I need possibility to create new tenant in my case(separate schema) new tenant equal new schema. I try to enable automatic migration stackoverflow.com/questions/13342516/… but it isn't working correct for me, in this case table is updated with new scheme, not create new one Commented Nov 12, 2016 at 20:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.