Skip to content
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

Updating entity mapped to JSONB column does not update the database #2744

Closed
andrewslavin opened this issue May 10, 2023 · 1 comment
Closed

Comments

@andrewslavin
Copy link

andrewslavin commented May 10, 2023

Steps to reproduce:

  1. Create an EF Core project with SomeEntity entity as described on this page https://www.npgsql.org/efcore/mapping/json.html#poco-mapping in the POCO mapping section.
  2. Add code that creates a new instance of SomeEntity and calls SaveChanges() to persist it to the database.
  3. Add code that reads SomeEntity back (on a different instance of DbContext), updates it as follows someEntity.Customer.Age = <different_number_from_what_it_currently_is>, and calls SaveChanges().

The expected outcome is that customer age will be updated in the DB, but actually no change happens. Looking at the entities in the ChangeTracker, I can see that SomeEntity is being tracked as Unchanged. I guess this is understandable - for EF to pick up the change, one of the SomeEntity instance properties needs to change. E.g. this produces the desired result: someEntity.Customer = new Customer { Age = <new_value>, <set all other props to old values>}.

Is there a way to make EF behave as expected? If not, it would be good to talk about this behaviour on the page I linked above.

@roji
Copy link
Member

roji commented Oct 28, 2024

Sorry for not answering here sooner.

Version 8.0 of the provider introduced support for the standard EF ToJson() support, which is generally better than Npgsql's traditional POCO mapping; as a result, the latter is now discouraged (see the 8.0 release notes, as well as the updated JSON docs).

Note that DOM mapping (via JsonDocument/JsonElement) may still make sense in some scenarios, and performing full change-tracking there is tracked by #3314.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants