From 1f8a5b256e03271ed88f40e9aa17314a98b432f8 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Thu, 3 Feb 2022 08:53:41 -0500 Subject: [PATCH] Bug fix: Defensive FirstOrDefault. #194 --- AppScaffolding/AppScaffolding.csproj | 2 +- DtoImporterService/BookImporter.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index 9a3c4647..fe015946 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net6.0 - 6.6.5.1 + 6.6.6.1 diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/BookImporter.cs index c67a38fb..e4f619ed 100644 --- a/DtoImporterService/BookImporter.cs +++ b/DtoImporterService/BookImporter.cs @@ -120,7 +120,8 @@ namespace DtoImporterService // 2+ : item.Categories[1].CategoryId; - var category = DbContext.Categories.Local.SingleOrDefault(c => c.AudibleCategoryId == lastCategory); + // This should properly be SingleOrDefault() not FirstOrDefault(), but FirstOrDefault is defensive + var category = DbContext.Categories.Local.FirstOrDefault(c => c.AudibleCategoryId == lastCategory); Book book; try