For our ASP.NET Core project we scaffold the existing database using the Scaffold-DbContext in the Package Manger console.
Every time we do the scaffolding, a context class is generated together with all the entities and it contains the OnConfiguring(..) method which calls optionsBuilder.UseSqlServer(..) to configure the context to connect to the SQL server database.
We have our connection string defined in the appsettings.json file and don't want to use the OnConfiguring(..) method, so the question is, if there is a way to automatically remove the OnConfiguring(..) method, so that we don't have to do that manually everytime we run the scaffolding.
The option you are searching for is: --no-onconfiguring
dotnet ef dbcontext scaffold
"server=.\SqlExpress;database=MyDb;Trusted_Connection=True"
Microsoft.EntityFrameworkCore.SqlServer
--no-onconfiguring
FYI there is a -NoOnConfiguring
option coming in EF Core 5.0
-NoOnConfiguring Don't generate DbContext.OnConfiguring. Added in EF Core 5.0.
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#scaffold-dbcontext
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With