IDesignTimeDbContextFactory not always needed?

.net-core asp.net-core-mvc c# entity-framework-core

Question

Previously i had to implement IDesignTimeDbContextFactory to get migrations running, e.g: PM > Add-Migration Initial PM > Update-Database

If not, the console threw an error and led me here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext#use-idesigntimedbcontextfactory.

So i did what it suggested and got migrations running. After that i have created new projects, and i didn't have to implement the IDesignTimeDbContextFactory. Migrations worked anyway. How is this possible? Same .NET Core version (2.0) on all of the projects.

Do we always need to create a IDesignTimeDbContextFactory, or is it just in certain situations?

Thanks!

1
3
9/13/2017 4:42:24 PM

Popular Answer

Okay, here it goes: If you have a default constructor in your DbContext or are using the Program.BuildWebHost() pattern established in the ASP.NET Core 2.0 project templates, you typically won't need an IDesignTimeDbContextFactory implementation.

In 2.0.0-preview1 Program.BuildWebHost() wasn't used and you needed a design-time factory.

See this thread for full discussion: https://github.com/aspnet/EntityFrameworkCore/issues/9033

4
9/14/2017 8:14:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow