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
Introduction. When using Entity Framework, the database connection string is stored in the app. config file by default, and the entity object references that to connect to the database. If, for any reason, a user needs to change the database, he can do so simply by editing that file prior to running the program.
After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.
In the Properties window, expand the Connection node. To quickly modify the connection string, edit the ConnectionString property, or click the down arrow on the Connection property and choose New Connection.
Creating or Updating the Database The Update command will create the database based on the context and domain classes and the migration snapshot, which is created using the add-migration or add command.
Are you looking for this? Edit: this is for EF 6.1
Update-Database –ConnectionString "Data Source=YourDatabaseServer; Initial Catalog=YourDatabase; Integrated Security=True;"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With