-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add JSON mapping for complex properties model building support #36299
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances Entity Framework Core’s relational database support for JSON mapping by introducing new extension methods and additional validation logic for complex properties and collections mapped to JSON columns. Key changes include new APIs for configuring JSON mappings (via ToJson and HasJsonPropertyName methods), updated validation logic to detect configuration conflicts, and expanded test coverage for these scenarios.
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexCollections.cs | Removed unused using directives. |
| test/EFCore.Relational.Tests/RelationalApiConsistencyTest.cs | Adjusted API consistency tests to reflect the new JSON mapping extensions. |
| test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.Json.cs | Added validation tests for various JSON mapping conflict scenarios. |
| test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalTestModelBuilderExtensions.cs | Introduced new extension methods for complex property and collection JSON mapping. |
| test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalModelBuilderTest.cs | Added tests for stored procedure and JSON mapping configurations. |
| test/EFCore.Relational.Specification.Tests/Migrations/MigrationsTestBase.cs | Added tests to verify table creation with JSON-mapped complex properties. |
| src/EFCore.Relational/Properties/RelationalStrings.resx | Updated resource strings for new JSON validation error messages. |
| src/EFCore.Relational/Metadata/Internal/RelationalModel.cs | Updated column mapping methods to pass the new type mapping parameter and clarify JSON column creation. |
| src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs | Revised JSON mapping validation logic for complex properties to handle conflict detection. |
| src/EFCore.Relational/Extensions/RelationalComplexTypeExtensions.cs, RelationalComplexPropertyExtensions.cs, RelationalComplexPropertyBuilderExtensions.cs, RelationalComplexCollectionBuilderExtensions.cs | Added extension methods to configure JSON mapping for complex types and collections. |
Files not reviewed (1)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
Comments suppressed due to low confidence (1)
src/EFCore.Relational/Metadata/Internal/RelationalModel.cs:624
- [nitpick] Consider adding an inline comment to explain the rationale behind disabling EF1001 in this block. This will help future maintainers understand why bypassing the internal API warning is necessary.
}
c0536bd to
7f3a1b1
Compare
src/EFCore.Relational/Extensions/RelationalComplexCollectionBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs
Outdated
Show resolved
Hide resolved
7f3a1b1 to
c81e674
Compare
Part of #31252
This pull request introduces enhancements to relational database support in Entity Framework Core by adding new extension methods and validation logic for complex properties and collections mapped to JSON columns.
New Extension Methods for JSON Mapping
Complex Collection Builder Extensions (
RelationalComplexCollectionBuilderExtensions.cs):ToJson) and map entity properties to specific JSON properties (HasJsonPropertyName). These methods support both generic and non-generic variants.Complex Property Builder Extensions (
RelationalComplexPropertyBuilderExtensions.cs):ToJson) and mapping them to specific JSON properties (HasJsonPropertyName). These methods also support generic and non-generic variants.Complex Property Metadata Extensions (
RelationalComplexPropertyExtensions.cs):Complex Type Metadata Extensions (
RelationalComplexTypeExtensions.cs):Validation Logic Enhancements
Property Mapping Validation (
RelationalModelValidator.cs):JSON Entity Validation (
RelationalModelValidator.cs):JSON Property Validation (
RelationalModelValidator.cs):