I have to create a table in code. The problem is, that I'm not allowed to use migrations. Application should check on start, whether the tables exist and add them on demand.
I have a very basic implementation of DbContext
which is created by calling this method:
public static ConfigurationDbContext CreateRemoteContext(string nameOrConnectionString)
{
var context = new ConfigurationDbContext(nameOrConnectionString);
context.Configuration.ProxyCreationEnabled = false;
context.Configuration.LazyLoadingEnabled = false;
context.Configuration.AutoDetectChangesEnabled = false;
return context;
}
And a configuration container, which gets passed to the rest parts of the application. It contains arrays for every table, that get loaded like this:
using (var dbContext = ConfigurationDbContext.CreateRemoteContext(App.Database.DbConnectionName))
{
var result = new ConfigurationContainer
{
ExistingTableEntities = dbContext.ExistingEntities.ToArray(),
...
NotExistingTableEntities = dbContext.NotExistingTableEntities.ToArray()
};
...
}
Here all of the entities get loaded to the configuration container. While trying to access a not existing table, is predictably throws an exception.
How can I check, whether the table exists and create it on demand without migration?