I am using the EF Core 2.0 CLI command scaffold-dbcontext to reverse engineer poco classes from an existing DB (database first). The project that contains my appsettings.json file with the ConnectionString is different from the project that holds the poco classes generated by scaffold-dbcontext.
How can I get the scaffold-dbcontext command to find the ConnectionString in the appsettings.json file of another project?
As stated in this you can now specify your connection string to be named, which looks like name=MyConnectionString
. The name of your connection string corresponds with the one defined in your appsettings.json
. Example:
Scaffold-DbContext -Connection name=MyDB -Provider Microsoft.EntityFrameworkCore.SqlServer
where in appsettings.json
you have something like this:
"ConnectionStrings": {
"MyDB": Server=mydb.database.windows.net;Database=mydb;Trusted_Connection=True;Encrypt=True;"
}