3

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

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

That is.. Awesome. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.