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:
- 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?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 17 (9 by maintainers)
Commits related to this issue
- Fix OriginalValues.Clone to really use original values Issue #7332 — committed to dotnet/efcore by ajcvickers 7 years ago
- Fix OriginalValues.Clone to really use original values Issue #7332 — committed to dotnet/efcore by ajcvickers 7 years ago
Note for triage: confirmed this is a bug.
@divega Not a regression. OriginalValues did not exist before 1.1. 😃