/// <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 MigrationFiles AddMigration( [NotNull] string name, [CanBeNull] string outputDir, [CanBeNull] string contextType) { Check.NotEmpty(name, nameof(name)); if (outputDir != null) { outputDir = Path.GetFullPath(Path.Combine(_projectDir, outputDir)); } var subNamespace = SubnamespaceFromOutputPath(outputDir); using var context = _contextOperations.CreateContext(contextType); var contextClassName = context.GetType().Name; if (string.Equals(name, contextClassName, StringComparison.Ordinal)) { throw new OperationException( DesignStrings.ConflictingContextAndMigrationName(name)); } var services = _servicesBuilder.Build(context); EnsureServices(services); EnsureMigrationsAssembly(services); var scaffolder = services.GetRequiredService <IMigrationsScaffolder>(); var migration = scaffolder.ScaffoldMigration(name, _rootNamespace, subNamespace, _language); var files = scaffolder.Save(_projectDir, migration, outputDir); return(files); }
/// <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 MigrationFiles AddMigration( string name, string?outputDir, string?contextType, string? @namespace) { Check.NotEmpty(name, nameof(name)); if (outputDir != null) { outputDir = Path.GetFullPath(Path.Combine(_projectDir, outputDir)); } var subNamespace = SubnamespaceFromOutputPath(outputDir); using var context = _contextOperations.CreateContext(contextType); var contextClassName = context.GetType().Name; if (string.Equals(name, contextClassName, StringComparison.Ordinal)) { throw new OperationException( DesignStrings.ConflictingContextAndMigrationName(name)); } var services = _servicesBuilder.Build(context); EnsureServices(services); EnsureMigrationsAssembly(services); using var scope = services.CreateScope(); var scaffolder = scope.ServiceProvider.GetRequiredService <IMigrationsScaffolder>(); var migration = string.IsNullOrEmpty(@namespace) // TODO: Honor _nullable (issue #18950) ? scaffolder.ScaffoldMigration(name, _rootNamespace ?? string.Empty, subNamespace, _language) : scaffolder.ScaffoldMigration(name, null, @namespace, _language); return(scaffolder.Save(_projectDir, migration, outputDir)); }