Improve entity history handling for shared types and JSON#24519
Merged
Improve entity history handling for shared types and JSON#24519
Conversation
Enhanced EntityHistoryHelper to correctly handle entities with shared CLR types and properties mapped to JSON. Added logic to determine property type from entry values when the type is object, and improved property change tracking for JSON-mapped navigation properties.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the EntityHistoryHelper class to properly handle entities with shared CLR types and properties mapped to JSON columns in Entity Framework Core. The implementation addresses three key scenarios: (1) detecting and using metadata names for shared type entities, (2) determining actual property types at runtime when the declared type is object, and (3) recursively tracking changes in JSON-mapped navigation properties.
Key Changes
- Added logic to detect shared CLR types and use metadata names instead of CLR type full names for entity identification
- Introduced
DeterminePropertyTypeFromEntrymethod to resolve actual property types from entry values when the declared type isobject - Implemented recursive property change tracking for JSON-mapped navigation properties to capture nested entity changes
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...lo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs
Show resolved
Hide resolved
...lo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs
Outdated
Show resolved
Hide resolved
...lo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs
Outdated
Show resolved
Hide resolved
…eworkCore/EntityHistory/EntityHistoryHelper.cs Co-authored-by: Copilot <[email protected]>
Refactored EntityHistoryHelper to better handle property changes for navigation properties mapped to JSON. Now, nested property changes are prefixed with the navigation property name, and duplicate property names are handled to avoid conflicts.
Update EntityHistoryHelper to set the entity type name only for shared CLR types that are not owned entities. This prevents incorrect entity name assignment for owned types.
Member
|
hi Can you add a unit test for the new method? |
Introduces AppEntityWithJsonProperty and related DbSet to test contexts, configures model to handle owned JSON properties, and adds tests to verify entity history tracking for nested JSON property changes and shared entities. Refactors EntityHistoryHelper to improve navigation property change handling.
This reverts commit 4d00ee9.
maliming
approved these changes
Dec 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Enhanced EntityHistoryHelper to correctly handle entities with shared CLR types and properties mapped to JSON. Added logic to determine property type from entry values when the type is object, and improved property change tracking for JSON-mapped navigation properties.