Skip to content
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

Query: Update original and current values of tracked objects' unchanged properties (MergeOptions.PreserveChanges) #35844

Open
Tracked by #22954
bricelam opened this issue Mar 25, 2025 · 2 comments

Comments

@bricelam
Copy link
Contributor

To use some ancient EF4 terminology, today's EF Core query behavior uses MergeOptions.AppendOnly. This means that new entities are materialized and attached to the state manager while any entities that already exist in the state manager (as identified by their key) are returned as is. This means that any new property values returned by the query are essentially discarded.

I would like the option of using the PreserveChanges behavior. This would update the original and current values of any existing entities' unchanged properties. This is obviously more computationally expensive, but I suspect it will be offset by the memory allocations saved in comparison to existing new-DbContext/NoTracking/ChangeTracker.Clear workarounds.

@roji
Copy link
Member

roji commented Mar 25, 2025

I seem to remember us discussing implementing such "merge" behavior in the past, @AndriySvyryd any idea if we have an issue already tracking this etc.?

Just noting that new-DbContext/NoTracking/ChangeTracker.Clear are about totally overriding the currently tracked entities - regardless of whether they've changed or not (whereas above you're proposing more of a merge, where only unchanged properties get updated with the new values from the database).

@bricelam
Copy link
Contributor Author

I seem to remember us discussing implementing such "merge" behavior in the past

Me too, lol. I searched every keyword I could think of but didn't find an existing issue.

Just noting that new-DbContext/NoTracking/ChangeTracker.Clear are about totally overriding the currently tracked entities

For sure. I'm just seeing a lot of cases where they're only being used in lieu of this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants