-
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
Changing the reference of an owned type to null is not saved #20558
Comments
@mark-glass In this case, EF can't tell the difference between the reference being null because it was always null, and the reference being null because it was non-null and then set to null. See the documentation for disconnected entities. |
Thank you for your prompt reply and thank you for the link to the documentation. In fact I had read the documentation before posting but it seems I missed the point. I thought I am in the scenario "Saving single entities"
and that by calling context.Update explicitly I tell EF that my entity has changed and that EF will find out the changes. In our real program we have a repository that reads the sqlite content in a context at program start and when the repository is saved it opens a new context and calls its Add,Update,Delete for some entities explicitly. If this non-recognition of the change of the reference for a disconnected entity is intented behavior of EF is there maybe any other way to tell EF that my entity changed? Do I have to tell EF explicitly that the reference was updated to null? |
@mark-glass I think the main issue you're running into is that owned types do not behave like value objects in many situations. See the discussion on this comment and the issues linked from #13947. So you will, in general, need to treat owned entities like other entities in this case--that is, you're dealing with a disconnected graph of entities, not the single entity case. |
Hello everbody,
Statement of the problem
I am quite new to EntityFramework but I guess I am encountering a problem when updating a reference of an owned type, that is not null, to null. This update is just not saved to the SQLite file.
This problem appears only in the case of a disconnected entity.
It is correctly tracked/saved if the entity is loaded and updated within a single context.
Please find below a minimal program demonstrating the problem.
Minimal program
Technical information
Microsoft.EntityFrameworkCore.Sqlite 3.1.3
Windows: 10
Visual Studio Version 16.4.6
Target framework: .NET core 3.1
The text was updated successfully, but these errors were encountered: