0
votes

I upgraded my ASP.NET project from Entity Framework Core 1.1. to Entity Framework Core 2.

I have a class library that targets the .net framework.

I have multiple DBContext in my class library

When I run the command Add-Migration MyMigration I get

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

I then run Add-Migration MyMigration -Context MyContext

I then get

Unable to create an object of type 'MyContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

This command use to work

1

1 Answers

2
votes

It seems like your upgrade not only Ef,but also Asp.Net CORE. Change your Program.cs file to:

public class Program
{
    public static void Main(string[] args)
    {
        var host = BuildWebHost(args);

        host.Run();
    }

    // Tools will use this to get application services
    public static IWebHost BuildWebHost(string[] args) =>
        new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
}