[release/7.0] Add back setter for scaffolded collection navigations #30343
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Port of #30311
Fixes #30286
Description
The generated code when reverse engineering (scaffolding) from an existing database was changed to drop the setter from collection navigation properties. The setter is not needed for EF use cases, so this made the generated code cleaner. However, it turns out that:
Customer impact
Multiple customers prefer the previously generated code, and, more importantly, System.Text.Json no longer serializes entities correctly. There is a workaround--customize the T4 template to add the setter.
How found
Multiple customer reports on 7.0.
Regression
Maybe, if you squint. This isn't a runtime code change; it requires the user to generate new code. However, the code generated is different than it used to be.
Testing
Tests updated.
Risk
Low. No quirk, because this is tooling code. However, the T4 template can be customized to generate whatever the user wants.