defensive FirstOrDefault
This commit is contained in:
parent
22548dc8ae
commit
5772d9c31e
1 changed files with 4 additions and 2 deletions
|
|
@ -66,9 +66,11 @@ namespace DtoImporterService
|
||||||
|
|
||||||
Category parentCategory = null;
|
Category parentCategory = null;
|
||||||
if (i == 1)
|
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)
|
if (category is null)
|
||||||
{
|
{
|
||||||
category = DbContext.Categories.Add(new Category(new AudibleCategoryId(id), name)).Entity;
|
category = DbContext.Categories.Add(new Category(new AudibleCategoryId(id), name)).Entity;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue