-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer value 0 is not set on INSERT when field has different default value #30463
Comments
And how do I mitigate this in the meantime? We've just migrated from full framework 4.7.2 with EF6 to net6 with EF7 and we have quite larget databases with default values in them. |
@DJDoena When do you want the database default value to be used? That is, if the property is set to some value, then do you want that value to be used instead of the default? Or do you want the database default value to always be used, regardless of what value the property has? |
@ajcvickers Basically the default values are from a bygone era but due to very specific audit reasons the DB cannot be easily changed. But if I set a value in my object I want it to be found in the DB later on. I understand the difficulty to distinguish between a |
@DJDoena Configure the property with |
When using SQL Server DB-first approach and defining a non-nullable integer field with default value 42:
then running a scaffold
the generated code for that table looks like this:
When trying to add a new row with a value of
0
for fieldIntWithDefault
the generatedINSERT
statement omits the field altogether.Any other value, including the database default of
42
produces the correctINSERT
statement:Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.4.4
The text was updated successfully, but these errors were encountered: