Unable to create an object of type 'MyContext'. For the different patterns supported at design time

前端 未结 9 3005
逝去的感伤
逝去的感伤 2021-02-19 16:42

I have ConsoleApplication on .NET Core and also i added my DbContext to dependencies, but howewer i have an error:

Unable to create an object of type \'My

9条回答
  •  暖寄归人
    2021-02-19 16:55

    I came across this problem today. In my case, the SqlDbContext was in a separate ASP.Net Core 3.1 class library project, and I was trying to setup migrations using the dotnet CLI from that project's root folder. The main web application, which is the default project, contains the connection string configuration inside the appsettings.json and the startup configurations therefore I had to specify the startup project path using the -s switch as follows.

    >dotnet ef migrations add initialcreation -s ..\MyWebApp\MyWebApp.csproj
    

    -s, short for startup project, is a quick alternative to implementing IDesignTimeDbContextFactory when the DbContext is in a different project than the web application project.

提交回复
热议问题