Rare duplicates are making their way into the db. Defensive FirstOrDefault added to address bug #184
This commit is contained in:
parent
5103240a76
commit
6b649cf4ca
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>6.6.3.1</Version>
|
<Version>6.6.4.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -209,7 +209,8 @@ namespace AudibleUtilities
|
|||||||
new Series
|
new Series
|
||||||
{
|
{
|
||||||
Asin = parent.Asin,
|
Asin = parent.Asin,
|
||||||
Sequence = parent.Relationships.Single(r => r.Asin == child.Asin).Sort.ToString(),
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive for malformed data from audible
|
||||||
|
Sequence = parent.Relationships.FirstOrDefault(r => r.Asin == child.Asin).Sort.ToString(),
|
||||||
Title = parent.TitleWithSubtitle
|
Title = parent.TitleWithSubtitle
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -94,7 +94,8 @@ namespace DtoImporterService
|
|||||||
// nested logic is required so order of names is retained. else, contributors may appear in the order they were inserted into the db
|
// nested logic is required so order of names is retained. else, contributors may appear in the order they were inserted into the db
|
||||||
var authors = item
|
var authors = item
|
||||||
.Authors
|
.Authors
|
||||||
.Select(a => DbContext.Contributors.Local.Single(c => a.Name == c.Name))
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive
|
||||||
|
.Select(a => DbContext.Contributors.Local.FirstOrDefault(c => a.Name == c.Name))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var narrators
|
var narrators
|
||||||
@ -104,7 +105,8 @@ namespace DtoImporterService
|
|||||||
// nested logic is required so order of names is retained. else, contributors may appear in the order they were inserted into the db
|
// nested logic is required so order of names is retained. else, contributors may appear in the order they were inserted into the db
|
||||||
: item
|
: item
|
||||||
.Narrators
|
.Narrators
|
||||||
.Select(n => DbContext.Contributors.Local.Single(c => n.Name == c.Name))
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive
|
||||||
|
.Select(n => DbContext.Contributors.Local.FirstOrDefault(c => n.Name == c.Name))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// categories are laid out for a breadcrumb. category is 1st, subcategory is 2nd
|
// categories are laid out for a breadcrumb. category is 1st, subcategory is 2nd
|
||||||
@ -154,7 +156,8 @@ namespace DtoImporterService
|
|||||||
var publisherName = item.Publisher;
|
var publisherName = item.Publisher;
|
||||||
if (!string.IsNullOrWhiteSpace(publisherName))
|
if (!string.IsNullOrWhiteSpace(publisherName))
|
||||||
{
|
{
|
||||||
var publisher = DbContext.Contributors.Local.Single(c => publisherName == c.Name);
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive
|
||||||
|
var publisher = DbContext.Contributors.Local.FirstOrDefault(c => publisherName == c.Name);
|
||||||
book.ReplacePublisher(publisher);
|
book.ReplacePublisher(publisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,8 @@ namespace DtoImporterService
|
|||||||
);
|
);
|
||||||
foreach (var name in newPeople)
|
foreach (var name in newPeople)
|
||||||
{
|
{
|
||||||
var p = groupby.Single(g => g.Name == name).People.First();
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive
|
||||||
|
var p = groupby.FirstOrDefault(g => g.Name == name).People.First();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@ -53,7 +53,8 @@ namespace DtoImporterService
|
|||||||
var newItem = gb.ImportItems.First();
|
var newItem = gb.ImportItems.First();
|
||||||
|
|
||||||
var libraryBook = new LibraryBook(
|
var libraryBook = new LibraryBook(
|
||||||
DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.DtoItem.ProductId),
|
// This should properly be Single() not FirstOrDefault(), but FirstOrDefault is defensive
|
||||||
|
DbContext.Books.Local.FirstOrDefault(b => b.AudibleProductId == newItem.DtoItem.ProductId),
|
||||||
newItem.DtoItem.DateAdded,
|
newItem.DtoItem.DateAdded,
|
||||||
newItem.AccountId);
|
newItem.AccountId);
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user