Skip to content

[Suggestion] Use a command line argument to handle migration #17

@darsenault77

Description

@darsenault77

Hey! Great Course BTW.

There is one thing I found so cumbersome that I had to go out of my way to fix it on my project, the commenting/uncommenting for migration to use SqlServer.

Here's how I handled it (note, my project is a "no startup" project, so some minor adaptation would be required in Startup).

In Program.cs

var dbProvider = builder.Configuration.GetValue("Provider", "InMemory");
if(builder.Environment.IsProduction() || dbProvider == "SqlServer") {
    // AddDbContext using SqlServer Database
} else {
    // AddDbContext using InMemory Database
}

When generating migrations
dotnet ef Migrations add {MigrationName} -- --provider SqlServer where {MigrationName} is the name of the migration you want to add.

Such a simple fix to avoid commenting/uncommenting every times you want to add a migration I thought I would share.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions