Entity Framework Core Interview Question #104

What are original values and current values in EF Core?

Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate

Quick Interview Answer

For tracked entities, EF Core can maintain the values originally loaded from the database and the values currently present on the entity.

Detailed Explanation

For tracked entities, EF Core can maintain the values originally loaded from the database and the values currently present on the entity.

These values are useful for change detection, auditing, concurrency handling, and determining exactly which properties were modified.

Original values belong to the lifetime of that tracked context; a new disconnected request does not automatically know the original values from a previous context.

Code Example

var entry = db.Entry(product);

var oldName = entry.Property(p => p.Name).OriginalValue;
var newName = entry.Property(p => p.Name).CurrentValue;