Visual Studio Code Entity Framework Core Add-Migration not recognized

前端 未结 5 1028
青春惊慌失措
青春惊慌失措 2021-02-02 09:53

I\'ve used yoman to generate an ASP.Net Core Web API application via the Visual Studio Code Editor. For reference, I followed this tutorial here

The API works fine. Ho

5条回答
  •  星月不相逢
    2021-02-02 10:23

    Im working on Mac, so Ruby is installed by default. My EF commands required lots of extra parameters --project, --startup-project etc. This was a pain to type every time, so I used rake to make this easier.

    In my project root, I added a file called rakefile with these contents:

    desc "Add Migraion"
    task :'add-migration' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef migrations add " + ARGV[1] + " --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj "
    end
    
    desc "Remove Migraion"
    task :'remove-migration' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef migrations remove --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj"
    end
    
    desc "Update Database"
    task :'update-database' do
        ARGV.each { |a| task a.to_sym do ; end }  
        puts ARGV[1]
        sh "dotnet ef database update --project MyProject.Data/MyProject.Data.csproj --startup-project MyProject.Web/MyProject.Web.csproj"
    end
    

    Then at the command line, I run these commands:

    rake add-migration 
    rake remove-migration
    rake update-database
    

提交回复
热议问题