Base solution for your next web application
Open Closed

How to Seed Data into Multi Tenant Database #1139


User avatar
0
maharatha created

I want to seed some tenant related data when a Tenant is created.

This is where I think I should seed data :

protected override void Seed(EntityFramework.CORPACCOUNTINGDbContext context) { context.DisableAllFilters();

        if (SeedMode == SeedMode.Host)
        {
            //Host seed
            new InitialHostDbBuilder(context).Create();

            //Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
        else if(SeedMode == SeedMode.Tenant)
        {
            // Here is where I plan to seed the data.
        }

        context.SaveChanges();
    }

But how do I get the tenant to insert data by Tenant


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    It seems there is a gap here. We will solve the problem in a short time. Follow this issue: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/issues/207">https://github.com/aspnetzero/aspnet-zero/issues/207</a>

  • User Avatar
    0
    maharatha created

    Thank You

  • User Avatar
    0
    john created

    Can you point me to the solution/Answer to your question. I need to seed newly created tables for each tenant. Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use the "New seed code sample:" in this comment <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/issues/207#issuecomment-219463858">https://github.com/aspnetzero/aspnet-ze ... -219463858</a>. Place your tenant seed code in this if block

    else if(SeedMode == SeedMode.Tenant)
    {
        //You can add seed for tenant databases...
    }