Closed aliensqueegee closed 2 years ago
Duplicate of #8695
@ajcvickers #8695 made me understand that at the moment EF Core tools don't have a proper way to read launchSettings.json file. If I'm running same code I posted in the original question into a ASP.NET Core Web Application, EF Core tools are successfully adding a migration and update the database (works with/without IDesignTimeDbContextFactory as well). So running same code in a console application doesn't work, but if I use a ASP.NET Core Web Application works fine. Any thought on this topic?
Hi all,
I don't understand why this ticket is closed. Author of the ticket says about appsetttings.Development.json file, but in supposedly duplicate ticket is said about launchSettings.json. Guys, they are not the same as you can guess. So at this moment, we can not take data from the configuration file, we have to set a hard code connection string. It is definitely great.
Thanks.
@pastore They are duplicates because they have the same root cause. If you have a bug that you think has a different root cause, then pleas open a new issue and please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
@ajcvickers Thanks
It is possible to implement IDesignTimeDbContextFactory which can then read connection string from appsettings.Development.json. Here is how:
Using Package Manager Console from Visual Studio, I want to add initial migration and update the database. I'm using basic dotnet core console application. Running Update-Database command in Package Manager Console fails.
Steps to reproduce
Create default .net core 3.1 console application in VS 2019.
csproj
appsettings.json
appsettings.Development.json
launchSettings.json
Program.cs
Running Add-Migration with IDesignTimeDbContextFactory commented generates
And Update-Database with IDesignTimeDbContextFactory commented generates
Running Add-Migration with IDesignTimeDbContextFactory uncommented generates
Running Update-Migration with IDesignTimeDbContextFactory uncommented generates
Further technical details
EF Core version: 3.1 Database provider: Microsoft.EntityFrameworkCore.SqlServer 3.1 Target framework: NET Core 3.1 Operating system: Windows 10 IDE: Visual Studio 2019 16.4.2