8

In ASP.NET Core and EF Core Code First, I have a multi-tenant webapp. When I create a new tenant, I want to change connection string, add migration on it and then update.

From command line, add migration can't get connection string dinamically on tenant and so i haven't a valid connection string for create a new database in the first time the app starts with a new tenant. Is there any solution for it? Thanks

2 Answers 2

3

Are you looking for this? Edit: this is for EF 6.1

Update-Database –ConnectionString "Data Source=YourDatabaseServer; Initial Catalog=YourDatabase; Integrated Security=True;"
Sign up to request clarification or add additional context in comments.

Comments

-1

I solved by inserting inside the DbContext constructor:

Database.EnsureCreated();

Thanks for your reply.

2 Comments

That's not a good solution. Every time an instance of your DbContext is created it will perform this check. You want to perform migrations once on startup. See my answer here stackoverflow.com/a/38283080/5782634
Thank you, your solution is better than mine. The important is to create at least one migration for each context.

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.