You can create two models for this. One for your database containing the tables that provide the database names, and the other for the other databases.
If you are using the db first approach, your context object will be created with a default connection string. Since it is a partial class you can extend it to take a connection string like so...
public partial class MyContext
{
public MyContext(string nameOrConnectionString) : base(nameOrConnectionString)
}
This is where at runtime you will pass the connection string of the server/database you pulled from the first context. Something like this is what it will look like...
...
using(var dbNameContext = new DatabaseNameContext())
{
var dbName = dbNameContext.DBNames.FirstOrDefault(dbn => dbn.Name == "db1");
var connectionString = "metadata=res://*/Database..." + dbName.Name;
using(var dbContexts = new MyContext(connectionString))
{
var MyDataList = dbContexts.Data.ToList();
}
}
Obviously you should fix the connection string to be like your own and place the dbName where it belongs in the connection string.
You should make sure you have a plan intact for keeping all of the different tables in different databases the same so that the model is accurate. Otherwise you will get RTEs.