From e0adbb0b711dbcc260446db03c4df4d362854188 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 16:47:12 +0700 Subject: [PATCH 1/8] fix Score Import --- Services/ImportBackgroundService.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 0f827fb..350c5cd 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -570,12 +570,23 @@ public class ImportBackgroundService : BackgroundService if (rec_import == null) throw new Exception("RecruitImport not found"); - if (rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null) + var rec_import_id = rec_import.Id; + var rec_import_year = rec_import.Year; + var hasExistingScores = rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null; + + if (hasExistingScores) { - await _context.BulkDeleteAsync(rec_import.ScoreImport.Scores.ToList()); + var existingScores = rec_import.ScoreImport.Scores.ToList(); + await _context.BulkDeleteAsync(existingScores); } - rec_import.ImportHostories.Add(new RecruitImportHistory + // Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking) + _context.ChangeTracker.Clear(); + + // Add history record using Attach stub for navigation (no explicit FK property on model) + var importStub = new RecruitImport { Id = rec_import_id }; + _context.Attach(importStub); + _context.RecruitImportHistories.Add(new RecruitImportHistory { Description = "นำเข้าข้อมูลผลคะแนนสอบ", CreatedAt = DateTime.Now, @@ -584,13 +595,15 @@ public class ImportBackgroundService : BackgroundService LastUpdatedAt = DateTime.Now, LastUpdateUserId = job.UserId ?? "", LastUpdateFullName = job.FullName ?? "System Administrator", + RecruitImport = importStub, }); // get doc from minio var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile)); var imported = new ScoreImport { - Year = rec_import.Year, + Year = rec_import_year, + RecruitImportId = rec_import_id, ImportFile = doc, CreatedAt = DateTime.Now, CreatedUserId = job.UserId ?? "", @@ -602,7 +615,7 @@ public class ImportBackgroundService : BackgroundService }; // Save ScoreImport parent first to get its Id - rec_import.ScoreImport = imported; + _context.ScoreImports.Add(imported); await _context.SaveChangesAsync(); _context.ChangeTracker.Clear(); From e8681834f256eee6c72e63284da6313fc7c31d43 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 16:53:27 +0700 Subject: [PATCH 2/8] fix again --- Services/ImportBackgroundService.cs | 32 +++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 350c5cd..acf058f 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -583,10 +583,8 @@ public class ImportBackgroundService : BackgroundService // Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking) _context.ChangeTracker.Clear(); - // Add history record using Attach stub for navigation (no explicit FK property on model) - var importStub = new RecruitImport { Id = rec_import_id }; - _context.Attach(importStub); - _context.RecruitImportHistories.Add(new RecruitImportHistory + // Add history record — set FK shadow property directly to avoid Attach side-effects + var historyEntry = _context.RecruitImportHistories.Add(new RecruitImportHistory { Description = "นำเข้าข้อมูลผลคะแนนสอบ", CreatedAt = DateTime.Now, @@ -595,24 +593,22 @@ public class ImportBackgroundService : BackgroundService LastUpdatedAt = DateTime.Now, LastUpdateUserId = job.UserId ?? "", LastUpdateFullName = job.FullName ?? "System Administrator", - RecruitImport = importStub, }); + historyEntry.Property("RecruitImportId").CurrentValue = rec_import_id; // get doc from minio var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile)); - var imported = new ScoreImport - { - Year = rec_import_year, - RecruitImportId = rec_import_id, - ImportFile = doc, - CreatedAt = DateTime.Now, - CreatedUserId = job.UserId ?? "", - CreatedFullName = job.FullName ?? "System Administrator", - LastUpdatedAt = DateTime.Now, - LastUpdateUserId = job.UserId ?? "", - LastUpdateFullName = job.FullName ?? "System Administrator", - Scores = new List() - }; + var imported = new ScoreImport(); + imported.Year = rec_import_year; + imported.RecruitImportId = rec_import_id; + imported.ImportFile = doc; + imported.CreatedAt = DateTime.Now; + imported.CreatedUserId = job.UserId ?? ""; + imported.CreatedFullName = job.FullName ?? "System Administrator"; + imported.LastUpdatedAt = DateTime.Now; + imported.LastUpdateUserId = job.UserId ?? ""; + imported.LastUpdateFullName = job.FullName ?? "System Administrator"; + imported.Scores = new List(); // Save ScoreImport parent first to get its Id _context.ScoreImports.Add(imported); From 13a8e309e76666fe91df5f6f6a240df999adbc0e Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 16:57:33 +0700 Subject: [PATCH 3/8] fix minio file --- Services/ImportBackgroundService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index acf058f..3c54528 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -596,12 +596,11 @@ public class ImportBackgroundService : BackgroundService }); historyEntry.Property("RecruitImportId").CurrentValue = rec_import_id; - // get doc from minio + // get doc from minio (MinIOService already saves Document to its own context) var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile)); var imported = new ScoreImport(); imported.Year = rec_import_year; imported.RecruitImportId = rec_import_id; - imported.ImportFile = doc; imported.CreatedAt = DateTime.Now; imported.CreatedUserId = job.UserId ?? ""; imported.CreatedFullName = job.FullName ?? "System Administrator"; @@ -610,8 +609,9 @@ public class ImportBackgroundService : BackgroundService imported.LastUpdateFullName = job.FullName ?? "System Administrator"; imported.Scores = new List(); - // Save ScoreImport parent first to get its Id - _context.ScoreImports.Add(imported); + // Save ScoreImport — use shadow FK for ImportFile to avoid re-inserting Document + var scoreEntry = _context.ScoreImports.Add(imported); + scoreEntry.Property("ImportFileId").CurrentValue = doc.Id; await _context.SaveChangesAsync(); _context.ChangeTracker.Clear(); From cba16f25b9e20ed0d540541a27c999e8df01b094 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 17:02:53 +0700 Subject: [PATCH 4/8] fix scoreimport --- Services/ImportBackgroundService.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 3c54528..4d4d4bc 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -572,12 +572,16 @@ public class ImportBackgroundService : BackgroundService var rec_import_id = rec_import.Id; var rec_import_year = rec_import.Year; - var hasExistingScores = rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null; + var existingScoreImport = rec_import.ScoreImport; - if (hasExistingScores) + if (existingScoreImport != null) { - var existingScores = rec_import.ScoreImport.Scores.ToList(); - await _context.BulkDeleteAsync(existingScores); + var existingScores = existingScoreImport.Scores?.ToList() ?? new List(); + if (existingScores.Count > 0) + await _context.BulkDeleteAsync(existingScores); + // Also delete the ScoreImport row itself (has unique index on RecruitImportId) + _context.ChangeTracker.Clear(); + await _context.BulkDeleteAsync(new List { existingScoreImport }); } // Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking) From 9c353f40c6c0080e9f70fd7a8a74fd1ec02835fb Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 17:07:27 +0700 Subject: [PATCH 5/8] fix fk --- Services/ImportBackgroundService.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 4d4d4bc..6841bc5 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -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()); From 054ef81c6366b91e987c807dc1c478ded91a75f7 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 17:14:39 +0700 Subject: [PATCH 6/8] update model and fix code --- Models/Recruits/RecruitScore.cs | 2 ++ Models/Recruits/ScoreImport.cs | 4 +++- Services/ImportBackgroundService.cs | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Models/Recruits/RecruitScore.cs b/Models/Recruits/RecruitScore.cs index 9698b3f..283bfd9 100644 --- a/Models/Recruits/RecruitScore.cs +++ b/Models/Recruits/RecruitScore.cs @@ -83,6 +83,8 @@ namespace BMA.EHR.Recruit.Models.Recruits [MaxLength(50), Comment("สถานะคัดกรองคุณสมบัติ")] public string ExamAttribute { get; set; } = string.Empty; + public Guid ScoreImportId { get; set; } + public ScoreImport ScoreImport { get; set; } } } diff --git a/Models/Recruits/ScoreImport.cs b/Models/Recruits/ScoreImport.cs index badee62..413f3f2 100644 --- a/Models/Recruits/ScoreImport.cs +++ b/Models/Recruits/ScoreImport.cs @@ -7,7 +7,9 @@ namespace BMA.EHR.Recruit.Models.Recruits { public int Year { get; set; } - public Document ImportFile { get; set; } = new Document(); + public Guid? ImportFileId { get; set; } + + public Document ImportFile { get; set; } public virtual List Scores { get; set; } = new List(); diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 6841bc5..64b1af8 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -615,9 +615,9 @@ public class ImportBackgroundService : BackgroundService imported.LastUpdateFullName = job.FullName ?? "System Administrator"; imported.Scores = new List(); - // Save ScoreImport — use shadow FK for ImportFile to avoid re-inserting Document - var scoreEntry = _context.ScoreImports.Add(imported); - scoreEntry.Property("ImportFileId").CurrentValue = doc.Id; + // Save ScoreImport — set ImportFileId FK directly (explicit property, not shadow) + imported.ImportFileId = doc.Id; + _context.ScoreImports.Add(imported); await _context.SaveChangesAsync(); _context.ChangeTracker.Clear(); @@ -713,7 +713,7 @@ public class ImportBackgroundService : BackgroundService // Set ScoreImportId FK for all scores in batch foreach (var score in batchScores) { - _context.Entry(score).Property("ScoreImportId").CurrentValue = scoreImport_id; + score.ScoreImportId = scoreImport_id; } await _context.BulkInsertAsync(batchScores); batchScores.Clear(); @@ -727,7 +727,7 @@ public class ImportBackgroundService : BackgroundService { foreach (var score in batchScores) { - _context.Entry(score).Property("ScoreImportId").CurrentValue = scoreImport_id; + score.ScoreImportId = scoreImport_id; } await _context.BulkInsertAsync(batchScores); } From d019ed588b7cf87652cd7e81d998aa2cd147d5e6 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 17:23:36 +0700 Subject: [PATCH 7/8] fix relation --- Data/ApplicationDbContext.cs | 1 + .../20260519102256_fix relation.Designer.cs | 1605 +++++++++++++++++ Migrations/20260519102256_fix relation.cs | 64 + .../ApplicationDbContextModelSnapshot.cs | 6 +- Models/Recruits/RecruitScore.cs | 2 + Services/ImportBackgroundService.cs | 7 +- 6 files changed, 1680 insertions(+), 5 deletions(-) create mode 100644 Migrations/20260519102256_fix relation.Designer.cs create mode 100644 Migrations/20260519102256_fix relation.cs diff --git a/Data/ApplicationDbContext.cs b/Data/ApplicationDbContext.cs index 81e4fd6..d386d19 100644 --- a/Data/ApplicationDbContext.cs +++ b/Data/ApplicationDbContext.cs @@ -20,6 +20,7 @@ namespace BMA.EHR.Recruit.Data modelBuilder.Entity().HasMany(x => x.Addresses).WithOne(x => x.Recruit).OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity().HasMany(x => x.Certificates).WithOne(x => x.Recruit).OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity().HasMany(x => x.Payments).WithOne(x => x.Recruit).OnDelete(DeleteBehavior.Cascade); + modelBuilder.Entity().HasMany(x => x.Scores).WithOne(x => x.ScoreImport).HasForeignKey(x => x.ScoreImportId).OnDelete(DeleteBehavior.Cascade); } public DbSet Documents { get; set; } diff --git a/Migrations/20260519102256_fix relation.Designer.cs b/Migrations/20260519102256_fix relation.Designer.cs new file mode 100644 index 0000000..770f155 --- /dev/null +++ b/Migrations/20260519102256_fix relation.Designer.cs @@ -0,0 +1,1605 @@ +// +using System; +using BMA.EHR.Recruit.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BMA.EHR.Recruit.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260519102256_fix relation")] + partial class fixrelation + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Documents.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)"); + + b.Property("Detail") + .IsRequired() + .HasColumnType("text"); + + b.Property("FileName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("FileSize") + .HasColumnType("int"); + + b.Property("FileType") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("ObjectRefId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.Recruit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("ApplyDate") + .HasColumnType("datetime(6)"); + + b.Property("CitizenCardExpireDate") + .HasColumnType("datetime(6)"); + + b.Property("CitizenCardIssuer") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("CitizenId") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("varchar(13)") + .HasComment("เลขประจำตัวประชาชน"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DateOfBirth") + .HasColumnType("datetime(6)"); + + b.Property("ExamId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("varchar(150)"); + + b.Property("Gendor") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("HddPosition") + .HasColumnType("longtext") + .HasComment("บัญชีสอบ"); + + b.Property("Isspecial") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("varchar(1)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("varchar(150)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Marry") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("ModifiedDate") + .HasColumnType("datetime(6)"); + + b.Property("National") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PositionLevel") + .HasColumnType("longtext"); + + b.Property("PositionName") + .HasColumnType("longtext"); + + b.Property("PositionType") + .HasColumnType("longtext"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Qualified") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("varchar(1)"); + + b.Property("Race") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("RecruitImportId") + .HasColumnType("char(36)"); + + b.Property("RefNo") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("Religion") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("typeTest") + .HasColumnType("longtext") + .HasComment("ประเภทการสอบภาค ก."); + + b.HasKey("Id"); + + b.HasIndex("RecruitImportId"); + + b.ToTable("Recruits"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitAddress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Address") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Address1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Amphur") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Amphur1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("District") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("District1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Mobile") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Moo") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Moo1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Province") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Province1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.Property("Road") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Road1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Soi") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Soi1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Telephone") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("ZipCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("ZipCode1") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitAddresses"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitCertificate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CertificateNo") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("ExpiredDate") + .HasColumnType("datetime(6)"); + + b.Property("IssueDate") + .HasColumnType("datetime(6)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitCertificates"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DocumentFileId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("DocumentFileId"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitDocuments"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitEducation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("BachelorDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Degree") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("GPA") + .HasColumnType("double"); + + b.Property("HighDegree") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Major") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("MajorGroupId") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("MajorGroupName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.Property("Specialist") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("varchar(1000)"); + + b.Property("University") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitEducations"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("AnnouncementDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(14) + .HasComment("วันที่ประกาศผลสอบ"); + + b.Property("AnnouncementEndDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(7) + .HasComment("วันสิ้นสุดประกาศ"); + + b.Property("AnnouncementStartDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(6) + .HasComment("วันเริ่มประกาศ"); + + b.Property("AuthName") + .HasColumnType("longtext"); + + b.Property("AuthPosition") + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Detail") + .HasColumnType("longtext") + .HasColumnOrder(4) + .HasComment("รายละเอียด"); + + b.Property("ExamDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(12) + .HasComment("วันที่สอบ"); + + b.Property("Fee") + .HasColumnType("int") + .HasColumnOrder(5) + .HasComment("ค่าธรรมเนียม"); + + b.Property("ImportFileId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250)") + .HasColumnOrder(2) + .HasComment("รอบการสอบ"); + + b.Property("Note") + .HasColumnType("text") + .HasColumnOrder(13) + .HasComment("หมายเหตุ"); + + b.Property("Order") + .HasColumnType("int") + .HasColumnOrder(3) + .HasComment("ครั้งที่"); + + b.Property("PaymentEndDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(9) + .HasComment("วันสิ้นสุดชำระเงิน"); + + b.Property("PaymentStartDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(8) + .HasComment("วันเริ่มชำระเงิน"); + + b.Property("RegisterEndDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(11) + .HasComment("วันสิ้นสุดสมัครสอบ"); + + b.Property("RegisterStartDate") + .HasColumnType("datetime(6)") + .HasColumnOrder(10) + .HasComment("วันเริ่มสมัครสอบ"); + + b.Property("Year") + .HasColumnType("int") + .HasColumnOrder(1) + .HasComment("ปีงบประมาณที่จัดสอบ"); + + b.HasKey("Id"); + + b.HasIndex("ImportFileId"); + + b.ToTable("RecruitImports"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DocumentId") + .HasColumnType("char(36)") + .HasComment("Id เอกสาร"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitImportId") + .HasColumnType("char(36)") + .HasComment("Id รอบสมัครสอบ"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("RecruitImportId"); + + b.ToTable("RecruitImportDocuments"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext") + .HasColumnOrder(1) + .HasComment("รายละเอียดการนำเข้า"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitImportId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitImportId"); + + b.ToTable("RecruitImportHistories"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DocumentId") + .HasColumnType("char(36)") + .HasComment("Id ไฟล์รูป"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitImportId") + .HasColumnType("char(36)") + .HasComment("Id รอบสมัครสอบ"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("RecruitImportId"); + + b.ToTable("RecruitImportImages"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitOccupation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Occupation") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Position") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.Property("Telephone") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("WorkAge") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Workplace") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitOccupations"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitPayment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("AccountNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Amount") + .HasColumnType("decimal(65,30)"); + + b.Property("BankCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("ChequeNo") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("ChqueBankCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("CompanyCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("CreditDebit") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("CustomerName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("PaymentId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PaymentType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("RecruitId") + .HasColumnType("char(36)"); + + b.Property("RefNo1") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("TellerId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("TermBranch") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("TextFile") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("TransDate") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("TransTime") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("RecruitId"); + + b.ToTable("RecruitPayments"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitScore", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("ABStatus") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง ผลประเมิน"); + + b.Property("AStatus") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง ผลประเมิน"); + + b.Property("BStatus") + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("CStatus") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง ผลประเมิน"); + + b.Property("CitizenId") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("varchar(13)") + .HasComment("เลขประจำตัวประชาชน"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("ExamAttribute") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("สถานะคัดกรองคุณสมบัติ"); + + b.Property("ExamId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("เลขประจำตัวสอบ"); + + b.Property("ExamStatus") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasComment("สอบได้ / ตก / ขาดสอบ"); + + b.Property("FullA") + .HasColumnType("int") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง คะแนนเต็ม"); + + b.Property("FullB") + .HasColumnType("int"); + + b.Property("FullC") + .HasColumnType("int") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง ทดสอบสมรรถนะ+ทดสอบจิตวิทยาฯ คะแนนเต็ม"); + + b.Property("FullD") + .HasColumnType("int") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง สัมภาษณ์ คะแนนเต็ม"); + + b.Property("FullScore") + .HasColumnType("int") + .HasComment("คะแนนเต็ม"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Major") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasComment("ลำดับที่สอบได้"); + + b.Property("PercentageA") + .HasColumnType("double") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง ร้อยละ"); + + b.Property("PercentageB") + .HasColumnType("double"); + + b.Property("PercentageC") + .HasColumnType("double") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง ร้อยละ"); + + b.Property("RemarkExamOrder") + .IsRequired() + .HasColumnType("longtext") + .HasComment("หมายเหตุจากลำดับที่สอบได้"); + + b.Property("RemarkScore") + .IsRequired() + .HasColumnType("longtext") + .HasComment("หมายเหตุจากบัญชีรวมคะแนน"); + + b.Property("ScoreImportId") + .HasColumnType("char(36)"); + + b.Property("SumA") + .HasColumnType("double") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง คะแนนรวม"); + + b.Property("SumAB") + .HasColumnType("double") + .HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง คะแนนรวม"); + + b.Property("SumB") + .HasColumnType("double"); + + b.Property("SumC") + .HasColumnType("double") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง ทดสอบสมรรถนะ+ทดสอบจิตวิทยาฯ คะแนนรวม"); + + b.Property("SumCD") + .HasColumnType("double") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง คะแนนรวมทดสอบสมรรถนะ+ทดสอบจิตวิทยาฯ และสัมภาษณ์"); + + b.Property("SumD") + .HasColumnType("double") + .HasComment("ภาคความเหมาะสมกับตำแหน่ง สัมภาษณ์ คะแนนรวม"); + + b.Property("TotalScore") + .HasColumnType("double") + .HasComment("คะแนนรวม"); + + b.HasKey("Id"); + + b.HasIndex("ScoreImportId"); + + b.ToTable("RecruitScores"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.ScoreImport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("ImportFileId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("RecruitImportId") + .HasColumnType("char(36)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ImportFileId"); + + b.HasIndex("RecruitImportId") + .IsUnique(); + + b.ToTable("ScoreImports"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.Recruit", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") + .WithMany("Recruits") + .HasForeignKey("RecruitImportId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("RecruitImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitAddress", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Addresses") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitCertificate", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Certificates") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitDocument", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "DocumentFile") + .WithMany() + .HasForeignKey("DocumentFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Documents") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DocumentFile"); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitEducation", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Educations") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImport", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "ImportFile") + .WithMany() + .HasForeignKey("ImportFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ImportFile"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportDocument", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") + .WithMany("RecruitDocuments") + .HasForeignKey("RecruitImportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("RecruitImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportHistory", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") + .WithMany("ImportHostories") + .HasForeignKey("RecruitImportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("RecruitImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImportImage", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") + .WithMany("RecruitImages") + .HasForeignKey("RecruitImportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("RecruitImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitOccupation", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Occupations") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitPayment", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.Recruit", "Recruit") + .WithMany("Payments") + .HasForeignKey("RecruitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recruit"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitScore", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Recruits.ScoreImport", "ScoreImport") + .WithMany("Scores") + .HasForeignKey("ScoreImportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ScoreImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.ScoreImport", b => + { + b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "ImportFile") + .WithMany() + .HasForeignKey("ImportFileId"); + + b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") + .WithOne("ScoreImport") + .HasForeignKey("BMA.EHR.Recruit.Models.Recruits.ScoreImport", "RecruitImportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ImportFile"); + + b.Navigation("RecruitImport"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.Recruit", b => + { + b.Navigation("Addresses"); + + b.Navigation("Certificates"); + + b.Navigation("Documents"); + + b.Navigation("Educations"); + + b.Navigation("Occupations"); + + b.Navigation("Payments"); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.RecruitImport", b => + { + b.Navigation("ImportHostories"); + + b.Navigation("RecruitDocuments"); + + b.Navigation("RecruitImages"); + + b.Navigation("Recruits"); + + b.Navigation("ScoreImport") + .IsRequired(); + }); + + modelBuilder.Entity("BMA.EHR.Recruit.Models.Recruits.ScoreImport", b => + { + b.Navigation("Scores"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20260519102256_fix relation.cs b/Migrations/20260519102256_fix relation.cs new file mode 100644 index 0000000..bf91e02 --- /dev/null +++ b/Migrations/20260519102256_fix relation.cs @@ -0,0 +1,64 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BMA.EHR.Recruit.Migrations +{ + /// + public partial class fixrelation : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_ScoreImports_Documents_ImportFileId", + table: "ScoreImports"); + + migrationBuilder.AlterColumn( + name: "ImportFileId", + table: "ScoreImports", + type: "char(36)", + nullable: true, + collation: "ascii_general_ci", + oldClrType: typeof(Guid), + oldType: "char(36)") + .OldAnnotation("Relational:Collation", "ascii_general_ci"); + + migrationBuilder.AddForeignKey( + name: "FK_ScoreImports_Documents_ImportFileId", + table: "ScoreImports", + column: "ImportFileId", + principalTable: "Documents", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_ScoreImports_Documents_ImportFileId", + table: "ScoreImports"); + + migrationBuilder.AlterColumn( + name: "ImportFileId", + table: "ScoreImports", + type: "char(36)", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + collation: "ascii_general_ci", + oldClrType: typeof(Guid), + oldType: "char(36)", + oldNullable: true) + .OldAnnotation("Relational:Collation", "ascii_general_ci"); + + migrationBuilder.AddForeignKey( + name: "FK_ScoreImports_Documents_ImportFileId", + table: "ScoreImports", + column: "ImportFileId", + principalTable: "Documents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Migrations/ApplicationDbContextModelSnapshot.cs b/Migrations/ApplicationDbContextModelSnapshot.cs index d849857..94e7f07 100644 --- a/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1353,7 +1353,7 @@ namespace BMA.EHR.Recruit.Migrations .HasColumnOrder(101) .HasComment("User Id ที่สร้างข้อมูล"); - b.Property("ImportFileId") + b.Property("ImportFileId") .HasColumnType("char(36)"); b.Property("LastUpdateFullName") @@ -1550,9 +1550,7 @@ namespace BMA.EHR.Recruit.Migrations { b.HasOne("BMA.EHR.Recruit.Models.Documents.Document", "ImportFile") .WithMany() - .HasForeignKey("ImportFileId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("ImportFileId"); b.HasOne("BMA.EHR.Recruit.Models.Recruits.RecruitImport", "RecruitImport") .WithOne("ScoreImport") diff --git a/Models/Recruits/RecruitScore.cs b/Models/Recruits/RecruitScore.cs index 283bfd9..93024f1 100644 --- a/Models/Recruits/RecruitScore.cs +++ b/Models/Recruits/RecruitScore.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace BMA.EHR.Recruit.Models.Recruits { @@ -83,6 +84,7 @@ namespace BMA.EHR.Recruit.Models.Recruits [MaxLength(50), Comment("สถานะคัดกรองคุณสมบัติ")] public string ExamAttribute { get; set; } = string.Empty; + [ForeignKey("ScoreImport")] public Guid ScoreImportId { get; set; } public ScoreImport ScoreImport { get; set; } diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 64b1af8..5f8119f 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -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 { 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) From 44c56c4a0a1c231ea98a6c85116ef651ca8f9c18 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 19 May 2026 17:37:42 +0700 Subject: [PATCH 8/8] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20error=20inser?= =?UTF-8?q?t=20score?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Services/ImportBackgroundService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Services/ImportBackgroundService.cs b/Services/ImportBackgroundService.cs index 5f8119f..7628ad0 100644 --- a/Services/ImportBackgroundService.cs +++ b/Services/ImportBackgroundService.cs @@ -664,6 +664,7 @@ public class ImportBackgroundService : BackgroundService if (string.IsNullOrEmpty(cell1)) break; var r = new RecruitScore(); + r.Id = Guid.NewGuid(); r.ExamId = reader.GetValue(1)?.ToString(); if (!string.IsNullOrEmpty(r.ExamId) && recruitsDict.TryGetValue(r.ExamId, out var recruit))