public bool RefreshEntity(bool isReload = true) { _logger.LogTrace("[{IsRefresh}] Start fetching tables and properties with config {@Configuration}.", isReload ? "REFRESH" : "INITIAL", _config); DbSchemaBuilder = new DbSchemaBuilder(_config, _logger); DynamicClassBuilder dynamicClassBuilder = new DynamicClassBuilder(_config, _logger); Type contextType = dynamicClassBuilder.CreateContextType(DbSchemaBuilder.Tables, _config.ConnectionString); Instance = (DbContextBase)Activator.CreateInstance(contextType); _logger.LogTrace("[{IsRefresh}] Dynamic data store is ready. Entity count: {Count}", isReload ? "REFRESH" : "INITIAL", DbSchemaBuilder.Tables.Count); return(true); }
void bg_DoWork(object sender, DoWorkEventArgs e) { try { dbSchemaBuilder = new DbSchemaBuilder(Config); dynamicClassBuilder = new DynamicClassBuilder(Config); ContextType = dynamicClassBuilder.CreateContextType(dbSchemaBuilder.Tables); Instance = (DbContextBase)Activator.CreateInstance(ContextType); Instance.Database.Connection.ConnectionString = Config.ConnectionString; IsActive = true; } catch (Exception exp) { IsActive = false; e.Cancel = true; throw exp; } }