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

(RC2) Persist Id values into owned collection JSON documents #34478

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

ajcvickers
Copy link
Contributor

Ports #34466 to 9.0

Fixes #29380

Description

Persisting entity types with an Id property did not work in previous releases of EF Core. This was an adoption blocker for many, as can be seen by the GitHub votes. This change is a targeted fix for 9 that allows Id properties to be persisted. It is too risky for 9 to do the wider fix of allowing key properties to be persisted.

Customer impact

Fixes a major adoption blocker for use of JSON in relational databases.

How found

Many customer reports

Regression

No

Testing

Id property added to existing model used by hundreds of tests.

Risk

Medium. This changes the model built, which we have discussed and analyzed and we think it's okay, especially since the model that was being built before was not valid. However, the model is used everywhere and it could have some impact that we have missed.

@ajcvickers ajcvickers requested a review from a team August 20, 2024 13:59
@ajcvickers
Copy link
Contributor Author

/cc @artl93

@AndriySvyryd AndriySvyryd changed the title (RC2) Persist Id values into owned collection JSON documents (#34466) (RC2) Persist Id values into owned collection JSON documents Aug 20, 2024
* Persist `Id` values into owned collection JSON documents

Fixes #29380

There are several aspects to #29380:
- Constructor binding (already fixed)
- Round-tripping the `Id` property value (addressed by this PR)
- Persisting key values in JSON collection documents (tracked by #28594)

I investigated persisting key values, but identity lookup requires key values in the materializer before we do the parsing of the document. This means persisted key values are not available without re-writing this part of the shaper, which we can't do for 9.

To fix the main issue (round-trip `Id`) this PR changes the way identity on owned JSON collection documents works. Instead of discovering and using the `Id` property, we treat it like any other property. We then create a shadow `__synthesizedOrdinal` property to act as the ordinal part of the key.

We need to discuss:
- Is this breaking for any scenario that was working before?
- Does this put us in a bad place for the future of owned types with explicit keys?

* Added validation of no explicit keys
@ajcvickers ajcvickers merged commit fc1ebc5 into release/9.0 Aug 21, 2024
7 checks passed
@ajcvickers ajcvickers deleted the Cherries branch August 21, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants