Default, Fake and DesignTime are just three out-of-the-box preconfigured ConnectionOptions that cover the standard use cases. You can create as many of your own as you need. The easiest way is to clone an existing one if you only need to change one or two things. So, let's say I want to setup TempHire with a Development, Test and Production DB and I want to be able to specify at runtime, which of the three DBs I want to connect to. To keep it simple, I have hardcoded connection strings in my Web.config for each of the three environments:
<connectionStrings>
<add name="TempHireEntities_DEV" connectionString="..." />
<add name="TempHireEntities_TEST" connectionString="..." />
<add name="TempHireEntities_PROD" connectionString="..." />
</connectionStrings>
The part after the underscore is the aforementioned DataSourceExtension, which lets you choose at runtime from a list of connections.
The first thing I do is create myself a ConnectionOptionsResolver that can produce the appropriate ConnectionOptions object for each of the environments.
public class EnvironmentResolver : IConnectionOptionsResolver
{
public ConnectionOptions GetConnectionOptions(string name)
{
if (name == "Development")
return ConnectionOptions.Default.WithDataSourceExtension("DEV").WithName("Development");
if (name == "Test")
return ConnectionOptions.Default.WithDataSourceExtension("TEST").WithName("Test");
if (name == "Production")
return ConnectionOptions.Default.WithDataSourceExtension("PROD").WithName("Production");
return null;
}
I simply clone ConnectionOptions.Default and change the DataSourceExtension and Name, because everything else stays the same in this case. The DataSourceExtension needs to match the part after the underscore in the connection strings above.
Now, when I create the EntityManagerProvider in the EntityManagerProviderFactory, I simply configure it with the correct environment.
[Export]
public IEntityManagerProvider<TempHireEntities> TempHireEntityManagerProvider
{
get
{
var provider = new EntityManagerProvider<TempHireEntities>()
.Configure(config => config.WithConnectionOptions("Test"));
return provider;
}
}
Instead of hardcoding the configuration, I would of course have a drop down on my login screen to let the user choose the environment and I store the user's selection somewhere where I can grab it from the EntityManagerProviderFactory.
Also, don't forget to configure the authentication service with the same ConnectionOptions, so you login against the correct environment.