Home:ALL Converter>EF Core - Create a migration without connection string

EF Core - Create a migration without connection string

Ask Time:2019-05-05T11:47:16         Author:si2030

Json Formatter

I have been ranging across multiple questions, tutorials and examples for something that fits this problem.

What if I don't know my connection string at the time I want to create my first initial migration? Given I am given the opportunity to set the connection string at the time of instantiating context eg:

var connection = @"Server=(localdb)\mssqllocaldb;Database=JobsLedgerDB;Trusted_Connection=True;ConnectRetryCount=0";
var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();
optionsBuilder.UseSqlServer(connection);

using (var context = new BloggingContext(optionsBuilder.Options))
{
  // do stuff
}

As described in the docs..

If you need to have a connection string to run migrations then for those situations where you don't have one (Tenant database where you get a connection string from a user account) how do you run an initial migration??

Do you create a dummy connection string to create the migration.. seems dodgy to me. I would love some input on this.

Author:si2030,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55988657/ef-core-create-a-migration-without-connection-string
yy