diff --git a/src/NzbDrone.Core/Datastore/BasicRepository.cs b/src/NzbDrone.Core/Datastore/BasicRepository.cs index cdc452284..2a073556a 100644 --- a/src/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/src/NzbDrone.Core/Datastore/BasicRepository.cs @@ -259,7 +259,7 @@ public virtual PagingSpec GetPaged(PagingSpec pagingSpec) protected virtual SortBuilder GetPagedQuery(QueryBuilder query, PagingSpec pagingSpec) { return query.Where(pagingSpec.FilterExpression) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()); + .OrderBy(pagingSpec.OrderByClause(x => x.Id), pagingSpec.ToSortDirection()); } protected void ModelCreated(TModel model) diff --git a/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs b/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs index 39cc5b7a6..5c0f072ce 100644 --- a/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs +++ b/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs @@ -6,9 +6,21 @@ namespace NzbDrone.Core.Datastore.Extensions { public static class PagingSpecExtensions { - public static Expression> OrderByClause(this PagingSpec pagingSpec) + public static Expression> OrderByClause(this PagingSpec pagingSpec, Expression> defaultExpression = null) { - return CreateExpression(pagingSpec.SortKey); + try + { + return CreateExpression(pagingSpec.SortKey); + } + catch + { + if (defaultExpression == null) + { + return x => x; + } + return defaultExpression; + } + } public static int PagingOffset(this PagingSpec pagingSpec) diff --git a/src/NzbDrone.Core/Movies/MovieRepository.cs b/src/NzbDrone.Core/Movies/MovieRepository.cs index 90502e39d..a64b008cf 100644 --- a/src/NzbDrone.Core/Movies/MovieRepository.cs +++ b/src/NzbDrone.Core/Movies/MovieRepository.cs @@ -161,7 +161,7 @@ public SortBuilder GetMoviesWithoutFilesQuery(PagingSpec pagingSpe { return Query.Where(pagingSpec.FilterExpression) .AndWhere(m => m.MovieFileId == 0) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + .OrderBy(pagingSpec.OrderByClause(x => x.SortTitle), pagingSpec.ToSortDirection()) .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); } @@ -179,7 +179,7 @@ private SortBuilder MoviesWhereCutoffUnmetQuery(PagingSpec pagingS return Query.Where(pagingSpec.FilterExpression) .AndWhere(m => m.MovieFileId != 0) .AndWhere(BuildQualityCutoffWhereClause(qualitiesBelowCutoff)) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + .OrderBy(pagingSpec.OrderByClause(x => x.SortTitle), pagingSpec.ToSortDirection()) .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); }