using Microsoft.EntityFrameworkCore.ChangeTracking; public void UpdateEntityProperty(EntityEntry entry, string propertyName, object newValue) { if (entry.State != EntityState.Modified) return; var currentValue = entry.Property(propertyName).GetCurrentValue(); // Compare the current value with the new value to decide if an update is required. if (currentValue != newValue) entry.Property(propertyName).CurrentValue = newValue; }
using Microsoft.EntityFrameworkCore.ChangeTracking; public void UpdateNavigationProperty(EntityEntry entry, string navigationPropertyName) { if (entry.State != EntityState.Modified) return; var currentValue = entry.Reference(navigationPropertyName).CurrentValue; // Do something with the current value... }Package library: Microsoft.EntityFrameworkCore.Core.