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

This commit is contained in:
Suphonchai Phoonsawat 2026-05-19 17:07:27 +07:00
parent cba16f25b9
commit 9c353f40c6

View file

@ -602,7 +602,9 @@ public class ImportBackgroundService : BackgroundService
// get doc from minio (MinIOService already saves Document to its own context)
var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile));
var scoreImport_id = Guid.NewGuid(); // Pre-generate Id to use as FK
var imported = new ScoreImport();
imported.Id = scoreImport_id;
imported.Year = rec_import_year;
imported.RecruitImportId = rec_import_id;
imported.CreatedAt = DateTime.Now;
@ -699,7 +701,6 @@ public class ImportBackgroundService : BackgroundService
r.LastUpdatedAt = DateTime.Now;
r.LastUpdateUserId = job.UserId ?? "";
r.LastUpdateFullName = job.FullName ?? "System Administrator";
r.ScoreImport = imported;
batchScores.Add(r);
}
@ -709,6 +710,11 @@ public class ImportBackgroundService : BackgroundService
if (batchCount >= batchSize)
{
// Set ScoreImportId FK for all scores in batch
foreach (var score in batchScores)
{
_context.Entry(score).Property("ScoreImportId").CurrentValue = scoreImport_id;
}
await _context.BulkInsertAsync(batchScores);
batchScores.Clear();
batchCount = 0;
@ -719,6 +725,10 @@ public class ImportBackgroundService : BackgroundService
// Process remaining records
if (batchScores.Count > 0)
{
foreach (var score in batchScores)
{
_context.Entry(score).Property("ScoreImportId").CurrentValue = scoreImport_id;
}
await _context.BulkInsertAsync(batchScores);
}
} while (reader.NextResult());