I have code for creating a database and applying migration:
public static (Server Server, string ConnectionString) InitializeServerAndDatabase(string databaseName, string defaultConnectionConnectionString, DbMigrationsConfiguration migrationsConfiguration)
{
var sqlConnection = new SqlConnection(defaultConnectionConnectionString);
var serverConnection = new ServerConnection(sqlConnection);
var server = new Server(serverConnection);
var database = new Database(server, databaseName);
database.Create();
var sqlConnectionStringBuilder = new SqlConnectionStringBuilder(defaultConnectionConnectionString);
sqlConnectionStringBuilder.InitialCatalog = databaseName;
var connectionString = sqlConnectionStringBuilder.ToString();
migrationsConfiguration.TargetDatabase = new DbConnectionInfo(connectionString, "System.Data.SqlClient");
var migrator = new DbMigrator(migrationsConfiguration);
var logger = new MigratorLoggingDecorator(migrator, new MinimalMigrationLogger());
logger.Update();
Environment.SetEnvironmentVariable("DefaultConnection", connectionString);
return (server, connectionString);
}
Since much more SQL was logged to start the migration than I wanted, I tried to minimize logging by writing MinimalMigrationsLoggerwhich is used in the method above:
public class MinimalMigrationLogger : MigrationsLogger
{
public override void Info(string message)
{
}
public override void Verbose(string message)
{
}
public override void Warning(string message)
{
Console.WriteLine(message);
}
}
However, I still get SQL in my logs to create the table and seed data. Why does my installation prevent this? How can I change it so that it does not record table creation and SQL seed data?
source
share