How can you perform EF migration without hard coding the nameconnectionString name in the database of the required constructor without parameters?
EF transitions force you to add a default constructor to your custom dbcontext. In the dbcontext database, you must specify the nameorconnection string.
public class CustomDbContext : DbContextBase { public CustomDbContext () : base("theconnectionstringwedontwanttoset")
The fact that we need to hard code the constructor is something we cannot work with, because in our client applications we work without a configuration file, and we dynamically increase the connection, because we connect to many different databases (server, local sql compact).
After studying the DbMigrationsConfiguration class, I found a DbConnectionsInfo property called TargetDatabase, which can be set in the constructor. But even this solution did not work. This is what I did:
public sealed class Configuration : DbMigrationsConfiguration<CustomDbContext> { public Configuration() { AutomaticMigrationsEnabled = true;
I see that Activator.CreateInstance is ultimately used in DbMigrator, and I expected from this class to use TargetDatabase.Create ... or something like that.
Any help or feedback is appreciated.
Thanks in advance,
Wilko
source share