I'm generating my Entity Framework C# classes using a database-first approach, and running the following in the Package Manager console:
Scaffold-DbContext "Server=[...];Database=[...];Integrated Security=True;Trusted_Connection=True;encrypt=false;TrustServerCertificate=true;"
Microsoft.EntityFrameworkCore.SqlServer
-Project Proj.EF -StartupProject Proj.EF.Updator
-Context Db4eeBaseContext -Force -OutputDir Db4_EE -UseDatabaseNames
I have .NET Core 2.1.2 installed and am running Visual Studio 2022, version 17.13.7.
We have columns in the database that are NOT NULL, yet have default values. The scaffolding makes these nullable properties, and shows this warning:
The column 'dbo.T_PERSON_RIDP.IS_ACTIVE' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint.
Is there a parameter I can pass to Scaffold-DbContext to have it NOT create nullable properties?
Reason: we are upgrading our EF code from old .edmx to new EF Core 6 and want our new database-first C# classes to be created the exact same way in order to make the migration easier. And removing those Default() values in the database isn't an option we can go with.
Falsevalue, and support insert with a defaulted value. The best solution is to bite that bullet and adjust your domain to work with the Required null-able Booleans.