private static void EnsureChangesDetected(EntityEntry entry) { var state = entry.State; var ctx = entry.Context; if (ctx.ChangeTracker.AutoDetectChangesEnabled && state == EfState.Modified) { return; } if ((ctx as HookingDbContext)?.IsInSaveOperation == true) { return; } if (state == EfState.Unchanged || state == EfState.Modified) { // When AutoDetectChanges is off we cannot be sure whether the entity is really unchanged, // because no detection was performed to verify this. entry.DetectChanges(); } }