/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual void DropDatabase(string?contextType) { using var context = CreateContext(contextType); var connection = context.Database.GetDbConnection(); _reporter.WriteInformation(DesignStrings.DroppingDatabase(connection.Database, connection.DataSource)); _reporter.WriteInformation( context.Database.EnsureDeleted() ? DesignStrings.DatabaseDropped(connection.Database) : DesignStrings.NotExistDatabase(connection.Database)); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual void DropDatabase([CanBeNull] string contextType) { using var context = CreateContext(contextType); var connection = context.Database.GetDbConnection(); _reporter.WriteInformation(DesignStrings.DroppingDatabase(connection.Database)); if (context.Database.EnsureDeleted()) { _reporter.WriteInformation(DesignStrings.DatabaseDropped(connection.Database)); } else { _reporter.WriteInformation(DesignStrings.NotExistDatabase(connection.Database)); } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void UpdateDatabase( [CanBeNull] string targetMigration, [CanBeNull] string contextType) { using (var context = _contextOperations.CreateContext(contextType)) { var services = _servicesBuilder.Build(context); EnsureServices(services); var migrator = services.GetRequiredService <IMigrator>(); migrator.Migrate(targetMigration); } _reporter.WriteInformation(DesignStrings.Done); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual void UpdateDatabase( string?targetMigration, string?connectionString, string?contextType) { using (var context = _contextOperations.CreateContext(contextType)) { if (connectionString != null) { context.Database.SetConnectionString(connectionString); } var services = _servicesBuilder.Build(context); EnsureServices(services); var migrator = services.GetRequiredService <IMigrator>(); migrator.Migrate(targetMigration); } _reporter.WriteInformation(DesignStrings.Done); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual void Log <TState>( LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { // Only show SQL when verbose if (_categoryName == DbLoggerCategory.Database.Command.Name && eventId.Id == RelationalEventId.CommandExecuted.Id) { logLevel = LogLevel.Debug; } var message = GetMessage(state, exception, formatter); switch (logLevel) { case LogLevel.Critical: case LogLevel.Error: _reporter.WriteError(message); break; case LogLevel.Warning: _reporter.WriteWarning(message); break; case LogLevel.Information: _reporter.WriteInformation(message); break; default: _reporter.WriteVerbose(message); break; } }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual void Log <TState>( LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { // Only show SQL when verbose if (_categoryName == typeof(RelationalCommandBuilderFactory).FullName && eventId.Id == (int)RelationalEventId.ExecutedCommand) { logLevel = LogLevel.Debug; } var message = GetMessage(state, exception, formatter); switch (logLevel) { case LogLevel.Critical: case LogLevel.Error: _reporter.WriteError(message); break; case LogLevel.Warning: _reporter.WriteWarning(message); break; case LogLevel.Information: _reporter.WriteInformation(message); break; default: _reporter.WriteVerbose(message); break; } }