fix relation
All checks were successful
Build & Deploy on Dev / build (push) Successful in 41s

This commit is contained in:
Suphonchai Phoonsawat 2026-05-19 17:23:36 +07:00
parent 054ef81c63
commit d019ed588b
6 changed files with 1680 additions and 5 deletions

View file

@ -580,8 +580,13 @@ public class ImportBackgroundService : BackgroundService
if (existingScores.Count > 0)
await _context.BulkDeleteAsync(existingScores);
// Also delete the ScoreImport row itself (has unique index on RecruitImportId)
// Use Remove+SaveChanges instead of BulkDelete since BulkDelete fails with detached entities
var scoreImportToDelete = existingScoreImport;
_context.ChangeTracker.Clear();
await _context.BulkDeleteAsync(new List<ScoreImport> { existingScoreImport });
var deleteStub = new ScoreImport { Id = scoreImportToDelete.Id };
_context.ScoreImports.Attach(deleteStub);
_context.ScoreImports.Remove(deleteStub);
await _context.SaveChangesAsync();
}
// Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking)