-
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
Owned property returned as null when all of its properties are null #20882
Comments
By design, see #9005 (comment) |
@smitpatel Your answer does not help me solve my issue. |
If you need to always create the owned referenced regardless of property values, hence making the dependent required see #12100 |
For anyone coming here with a similiar problem, I made a simple workaround, until #12100 feature is released. |
I had same problem in my project. I just have defined default value in my private constructor. It was suitable for me. |
Inside my entity
Submission
:I have an owned entity of type
ObjectData
:Their relationship is configured inside the
Context.OnModelCreating
like so:When a
Submission = { ObjectData = { ObjectCategoryType = null, ObjectCost = null } }
is persisted, and then later fetched from the database, it will return as aSubmission = { ObjectData = null }
.I expected it to return as
Submission = { ObjectData = { ObjectCategoryType = null, ObjectCost = null } }
.It seems that EFCore determines if the owned entity is null by checking if all of its columns have null values, instead of differentiating between an "empty" owned property and a null owned property.
I need the ObjectData to always exist and all of its properties to be nullable. Any ideas on how to remedy this?
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer v3.1.3
Target framework: .NET Framework 4.8 / .NET Framework 3.1
The text was updated successfully, but these errors were encountered: