I'm a bit confused by the (sparse) MSDN documentation on EF6 code-based configuration. I have a WPF application that needs to create an SQL connection based on command-line parameters and/or user input from a dialog. In older versions of EF I accomplished this by building the connection string and passing it to my derived DbContext every time.
It would be nice if I could avoid having to do that, since it also means having to pass the connection string to every view model that needs to use the context. It seems like the DbConfig in EF6 is on the path to accomplish that. Based on the docs, I have created a custom class that simply looks like this:
public class EfConfiguration: DbConfiguration
{
public EfConfiguration()
{
SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
SetDefaultConnectionFactory(new SqlConnectionFactory());
SetDatabaseInitializer<DataContext>(null);
}
}
Which, from my understanding, EF will pickup and do something with. But my question is, how do I then set the connection string once the application is running? And in doing so, does that mean I can now instantiate my DbContext with no parameters?