-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Implement MergeOption #36556
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
base: main
Are you sure you want to change the base?
Implement MergeOption #36556
Conversation
…onger necessary if all entity classes in the model are defined with a change-tracking strategy other than "ChangeTrackingStrategy.Snapshot." This is controlled in the ProcessModelFinalizing method of the ChangeTrackingStrategyConvention class. DetectChanges is therefore not called when saving because change tracking is performed using the EntityReferenceMap (_entityReferenceMap property), which essentially corresponds to the previous caching mechanism using EntityState dictionaries from EF4/5/6. However, querying this cache was not enabled; instead, users were forced to use ChangeTracker.Entries(), which returned all objects and led to performance problems with large long-term contexts. This change now enables fast access to changed objects using the new GetEntriesForState method in the ChangeTracker class. This, in turn, calls EntityReferenceMap.GetEntriesForState(), which already exists. For fast change tracking, implement INotifyProperty-Changed on your entity classes and activate this strategy in the Model Builder using ChangeTrackingStrategy.ChangedNotifications via HasChangeTrackingStrategy(). dotnet#31819
This needs to target |
@dotnet-policy-service agree |
As this seems to be a new feature, there's very little chance we'll be backporting this to 9.0. In fact, the window for introducing new features into 10.0 is also closing very soon, so this will most likely be considered for 11.0 at the earliest. |
Do I need to do anything else on my side, or can you handle the remaining work yourself so it can be included in release 10 or 11? (I'm asking because I'm not familiar with GitHub workflows or merging into the main branch.) |
As @cincuranet wrote above, you need retarget this PR against main - it's currently targeting release/9.0. And as I wrote above, this will almost certainly not going into EF 10 (or 9). |
@cincuranet How can I "retarget to main"? Do you have any instructions? |
Rebase your changes on top of |
…onger necessary if all entity classes in the model are defined with a change-tracking strategy other than "ChangeTrackingStrategy.Snapshot." This is controlled in the ProcessModelFinalizing method of the ChangeTrackingStrategyConvention class. DetectChanges is therefore not called when saving because change tracking is performed using the EntityReferenceMap (_entityReferenceMap property), which essentially corresponds to the previous caching mechanism using EntityState dictionaries from EF4/5/6. However, querying this cache was not enabled; instead, users were forced to use ChangeTracker.Entries(), which returned all objects and led to performance problems with large long-term contexts. This change now enables fast access to changed objects using the new GetEntriesForState method in the ChangeTracker class. This, in turn, calls EntityReferenceMap.GetEntriesForState(), which already exists. For fast change tracking, implement INotifyProperty-Changed on your entity classes and activate this strategy in the Model Builder using ChangeTrackingStrategy.ChangedNotifications via HasChangeTrackingStrategy(). dotnet#31819
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.
This needs a significant number of new tests to be added.
- Some tests for
GetEntriesForState
to exercise each parameter - A new test class for
Refresh
-test\EFCore.Specification.Tests\MergeOptionTestBase.cs
- It should cover the following cases:
- Existing entries in all states
- Unchanged entries with original value set to something that doesn't match the database state
- Modified entries with properties marked as modified, but with the original value set to something that matches the database state
- Owned entity that was replaced by a different instance, so it's tracked as both Added and Deleted
- A derived entity that was replaced by a base entity with same key value
- Different terminating operators:
ToList
,FirstOrDefault
, etc... - Streaming (non-buffering) query that's consumed one-by-one
- Queries with
Include
,Include
with filter andThenInclude
- Projecting a related entity in
Select
withoutInclude
- Creating a new instance of the target entity in
Select
with calculated values that are going to be client-evaluated - Projecting an entity multiple times in
Select
with same key, but different property values - Lazy-loading proxies with navigations in loaded and unloaded states
- Non-tracking queries should throw
- Multiple
Refresh
with different values in the same query should throw
- The test model should incorporate the following features:
- Collection and non-collection owned types
- Collection and non-collection complex properties of value and reference types
- Many-to-many relationships without an explicit join type
- Global query filters
- Shadow and non-shadow properties
- Properties mapped to computed columns
- Properties with value converters
- Primitive collections
- Table-sharing with shared non-key columns
- It should cover the following cases:
Issue #31819 "DetectChanges slow in long-term contexts" is no longer necessary if all entity classes in the model are defined with a change-tracking strategy other than "ChangeTrackingStrategy.Snapshot." This is controlled in the ProcessModelFinalizing method of the ChangeTrackingStrategyConvention class. DetectChanges is therefore not called when saving because change tracking is performed using the EntityReferenceMap (_entityReferenceMap property), which essentially corresponds to the previous caching mechanism using EntityState dictionaries from EF4/5/6. However, querying this cache was not enabled; instead, users were forced to use ChangeTracker.Entries(), which returned all objects and led to performance problems with large long-term contexts. This change now enables fast access to changed objects using the new GetEntriesForState method in the ChangeTracker class. This, in turn, calls EntityReferenceMap.GetEntriesForState(), which already exists.
Issue #16491: Implemented legacy Merge-Option Feature from EF/4/5/6