From 3cee1307fca0a47a42d2b94df653ec259099b61d Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Wed, 27 May 2026 13:21:56 -0400 Subject: [PATCH] Fix customer import: normalize blank email to null, not empty string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UNIQUE index on (CompanyId, Email) uses HasFilter([Email] IS NOT NULL), so NULL allows multiple rows but empty string '' does not — every blank-email customer after the first was hitting a duplicate-key violation at save time. Co-Authored-By: Claude Sonnet 4.6 --- .../Services/CsvImportService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PowderCoating.Infrastructure/Services/CsvImportService.cs b/src/PowderCoating.Infrastructure/Services/CsvImportService.cs index a86276d..b9a3ffe 100644 --- a/src/PowderCoating.Infrastructure/Services/CsvImportService.cs +++ b/src/PowderCoating.Infrastructure/Services/CsvImportService.cs @@ -480,7 +480,12 @@ public class CsvImportService : ICsvImportService { // Strip any literal quote characters that QB/Excel may wrap around field values var cleanCompanyName = StripQuotes(record.CompanyName); - var cleanEmail = StripQuotes(record.Email); + // Normalise to null (not empty string) — the UNIQUE index on (CompanyId, Email) + // uses HasFilter("[Email] IS NOT NULL"), so NULL is allowed for multiple rows + // but "" (empty string) is not NULL and would cause a unique-constraint violation + // on the second blank-email customer saved. + var rawEmail = StripQuotes(record.Email); + var cleanEmail = string.IsNullOrWhiteSpace(rawEmail) ? null : rawEmail; var firstName = StripQuotes(record.ContactFirstName)?.Trim(); var lastName = StripQuotes(record.ContactLastName)?.Trim();