0

I am using .net core entity framework.

I have multi tenant dbs. so I have kept one root tenant db as base. and I want to replicate those schema changes to all other dbs using entity framework. I am generating my models using following command.

Scaffold-DbContext "Data Source=(local);Initial Catalog=sampleTenantDb;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Tenants -Force

So when creating new tenant, I simply use

context.Database.EnsureCreated();

But when I add new table in code, I want to apply it to all tenants. So how do I do it?

I tried following but, it doesn't work (not adding remanining tables)

myDbContext.Database.Migrate();

2 Answers 2

1

If your DbContext is created with Scaffold-DbContext, it won't have any Migrations. That's for a database-first workflow, in which you would apply the DDL changes to the tenant databases with a script, perhaps created with SQL Server Data Tools.

Sign up to request clarification or add additional context in comments.

Comments

1

You have need to create multiple dbcontext object and and pass connection string in that way you can update multiple db

Comments

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.