Fix customer import: normalize blank email to null, not empty string
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 <noreply@anthropic.com>
This commit is contained in:
@@ -480,7 +480,12 @@ public class CsvImportService : ICsvImportService
|
|||||||
{
|
{
|
||||||
// Strip any literal quote characters that QB/Excel may wrap around field values
|
// Strip any literal quote characters that QB/Excel may wrap around field values
|
||||||
var cleanCompanyName = StripQuotes(record.CompanyName);
|
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 firstName = StripQuotes(record.ContactFirstName)?.Trim();
|
||||||
var lastName = StripQuotes(record.ContactLastName)?.Trim();
|
var lastName = StripQuotes(record.ContactLastName)?.Trim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user