Skip to content

Conversation

@AndriySvyryd
Copy link
Member

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):

    • Added methods to configure complex collections to be stored as JSON columns (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):

    • Added similar methods for configuring complex properties to be stored as JSON columns (ToJson) and mapping them to specific JSON properties (HasJsonPropertyName). These methods also support generic and non-generic variants.
  • Complex Property Metadata Extensions (RelationalComplexPropertyExtensions.cs):

    • Added methods to get, set, and validate JSON property names for complex properties mapped to JSON columns. These include support for configuration sources and data annotations.
  • Complex Type Metadata Extensions (RelationalComplexTypeExtensions.cs):

    • Added methods to set and retrieve container column names for complex types, including support for configuration sources and data annotations.

Validation Logic Enhancements

  • Property Mapping Validation (RelationalModelValidator.cs):

    • Enhanced validation to ensure that complex properties mapped to JSON columns do not have conflicting configurations, such as both JSON property names and explicit column names. Added checks for invalid configurations like JSON property names without JSON mapping.
  • JSON Entity Validation (RelationalModelValidator.cs):

    • Refactored validation logic for entities mapped to JSON columns to handle conflicts in JSON column mappings and ensure proper configuration of complex properties within JSON entities.
  • JSON Property Validation (RelationalModelValidator.cs):

    • Added detailed validation for JSON properties to check for duplicate mappings, default values, and conflicts between column names and JSON property names.

@AndriySvyryd AndriySvyryd requested a review from Copilot June 25, 2025 22:56
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner June 25, 2025 22:56
Copy link

Copilot AI left a 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.
        }

@AndriySvyryd AndriySvyryd force-pushed the Issue31252_ModelBuilding branch from c0536bd to 7f3a1b1 Compare June 25, 2025 23:04
@AndriySvyryd AndriySvyryd force-pushed the Issue31252_ModelBuilding branch from 7f3a1b1 to c81e674 Compare June 27, 2025 21:56
@AndriySvyryd AndriySvyryd enabled auto-merge (squash) June 27, 2025 21:57
@AndriySvyryd AndriySvyryd merged commit 4d458fb into main Jul 2, 2025
7 checks passed
@AndriySvyryd AndriySvyryd deleted the Issue31252_ModelBuilding branch July 2, 2025 19:41
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

Successfully merging this pull request may close these issues.

3 participants