efcore: EntityEntry.OriginalValues APIs incorrectly return current values

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?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Note for triage: confirmed this is a bug.

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