diff --git a/src/NzbDrone.Core/Books/Repositories/BookRepository.cs b/src/NzbDrone.Core/Books/Repositories/BookRepository.cs index dd21614b0..46aba94ac 100644 --- a/src/NzbDrone.Core/Books/Repositories/BookRepository.cs +++ b/src/NzbDrone.Core/Books/Repositories/BookRepository.cs @@ -70,7 +70,8 @@ namespace NzbDrone.Core.Books public List GetBooksByFileIds(IEnumerable fileIds) { return Query(new SqlBuilder() - .Join((l, r) => l.Id == r.EditionId) + .Join((b, e) => b.Id == e.BookId) + .Join((l, r) => l.Id == r.EditionId) .Where(f => fileIds.Contains(f.Id))) .DistinctBy(x => x.Id) .ToList(); @@ -90,7 +91,8 @@ namespace NzbDrone.Core.Books #pragma warning disable CS0472 private SqlBuilder AlbumsWithoutFilesBuilder(DateTime currentTime) => Builder() .Join((l, r) => l.AuthorMetadataId == r.AuthorMetadataId) - .LeftJoin((t, f) => t.Id == f.EditionId) + .Join((b, e) => b.Id == e.BookId) + .LeftJoin((t, f) => t.Id == f.EditionId) .Where(f => f.Id == null) .Where(a => a.ReleaseDate <= currentTime); #pragma warning restore CS0472 @@ -107,7 +109,8 @@ namespace NzbDrone.Core.Books private SqlBuilder AlbumsWhereCutoffUnmetBuilder(List qualitiesBelowCutoff) => Builder() .Join((l, r) => l.AuthorMetadataId == r.AuthorMetadataId) - .Join((t, f) => t.Id == f.EditionId) + .Join((b, e) => b.Id == e.BookId) + .LeftJoin((t, f) => t.Id == f.EditionId) .Where(BuildQualityCutoffWhereClause(qualitiesBelowCutoff)); private string BuildQualityCutoffWhereClause(List qualitiesBelowCutoff) @@ -193,7 +196,8 @@ namespace NzbDrone.Core.Books public List GetAuthorBooksWithFiles(Author author) { return Query(Builder() - .Join((t, f) => t.Id == f.EditionId) + .Join((b, e) => b.Id == e.BookId) + .Join((t, f) => t.Id == f.EditionId) .Where(x => x.AuthorMetadataId == author.AuthorMetadataId)); } }