EntityEntry.OriginalValues APIs incorrectly return current values
See original GitHub issueREcently I ported some EF code to EF Core, and noticed these behaviors. After changing a tracked entity, get its EntityEntry object, then:
- EntityEntry.OriginalValues.Clone() In EF, it return a clone of original values. In EF Core, it returns a clone of current values. Workaround in EF Core:
var originalValues = entry.OriginalValues.Clone(); // Return current values.
originalValues.SetValues(entry.OriginalValues); // Now original values.
- EntityEntry.OriginalValues.ToObject() In EF, it returns an entity with original values. In EF Core, it returns an entity with current values. Workaround in EF Core:
var originalValues = entry.OriginalValues.Clone();
originalValues.SetValues(entry.OriginalValues);
Product original = (Product)originalValues.ToObject();
Are these bugs, or am I using it in a wrong way?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:17 (9 by maintainers)
Top Results From Across the Web
EntityEntry.OriginalValues APIs incorrectly return current ...
In EF Core, it returns an entity with current values. Workaround in EF Core: var originalValues = entry.OriginalValues.Clone(); originalValues.
Read more >EntityEntry.OriginalValues.ToObject() is the same as ...
When I try to access the original values of the object in an overridden SaveChangesAsync with EntityEntry.OriginalValues.ToObject(), I see that ...
Read more >Compare Original and Current Values Before Save in EF
To get the original and current values of an entity, you need to get its EntityEntry from the ChangeTracker. You can use the...
Read more >Change Detection and Notifications - EF Core
This detection of changes happens when SaveChanges is called to ensure all changed values are detected before sending updates to the database.
Read more >Entity Change Tracking using DbContext in ...
When the call to SaveChanges is made, Entity Framework is aware of what values have changed, what the new values are, and what...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Note for triage: confirmed this is a bug.
@divega Not a regression. OriginalValues did not exist before 1.1. 😃