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)