.NET Core Entity Framework - Migration path --output-dir

.net .net-core asp.net-core entity-framework entity-framework-core


I have successfully created a migration file using .NET Core class library by using command: dotnet ef --startup-project ../Project.Web migrations add Init

Because I register my db context in a different layer, (web layer), and have class library, I have to set my startup project to Project.Web.

After creating my initial migration it looks something like this:

enter image description here

But now I would like to move the migration folder Project.Data/Migrations to Project.Data/Database/Migrations

I have tried using the output-dir parameter:

dotnet ef --startup-project ../Project.Web --output-dir Database migrations add Init

But then I get:

dotnet : Unrecognized option '--output-dir'

Startup (in a different project, business layer)

public static IServiceCollection InjectBusinessContext(this IServiceCollection services, string connectionString)
    services.AddEntityFrameworkSqlServer().AddDbContext<ProjectContext>((serviceProvider, options) => options.UseSqlServer(connectionString, b => b.MigrationsAssembly("Database")).UseInternalServiceProvider(serviceProvider));

    return services;

Context (data layer)

public class ProjectContext : DbContext
    public ProjectContext(DbContextOptions<ProjectContext> options) : base(options)

    public DbSet<Account> Account { get; set; }
2/14/2017 9:28:35 PM

Accepted Answer

Just move it (and optionally change the namespace of the classes). New migrations will follow suit with the previous migration. (Ditto for the model snapshot.) Yes, it's that awesome. ;)

2/15/2017 4:31:05 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow