From 5772d9c31efa64c2d46ed9d6cd2e09d78a5ecde6 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 5 Oct 2021 10:07:58 -0400 Subject: [PATCH] defensive FirstOrDefault --- DtoImporterService/CategoryImporter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DtoImporterService/CategoryImporter.cs b/DtoImporterService/CategoryImporter.cs index f778e813..5980ee85 100644 --- a/DtoImporterService/CategoryImporter.cs +++ b/DtoImporterService/CategoryImporter.cs @@ -66,9 +66,11 @@ namespace DtoImporterService Category parentCategory = null; if (i == 1) - parentCategory = DbContext.Categories.Local.Single(c => c.AudibleCategoryId == pair[0].CategoryId); + // should be "Single()" but user is getting a strange error + parentCategory = DbContext.Categories.Local.FirstOrDefault(c => c.AudibleCategoryId == pair[0].CategoryId); - var category = DbContext.Categories.Local.SingleOrDefault(c => c.AudibleCategoryId == id); + // should be "SingleOrDefault()" but user is getting a strange error + var category = DbContext.Categories.Local.FirstOrDefault(c => c.AudibleCategoryId == id); if (category is null) { category = DbContext.Categories.Add(new Category(new AudibleCategoryId(id), name)).Entity;