Reft
Reft

Reputation: 2433

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

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; }
}

Upvotes: 3

Views: 5191

Answers (1)

bricelam
bricelam

Reputation: 30375

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. ;)

Upvotes: 5

Related Questions