question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EntityEntry.OriginalValues APIs incorrectly return current values

See original GitHub issue

REcently I ported some EF code to EF Core, and noticed these behaviors. After changing a tracked entity, get its EntityEntry object, then:

  1. 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.
  1. 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ajcvickerscommented, Jan 4, 2017

Note for triage: confirmed this is a bug.

1reaction
ajcvickerscommented, Jan 9, 2017

@divega Not a regression. OriginalValues did not exist before 1.1. 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found