1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

More better joins, some minor MDM changes for paging

This commit is contained in:
Mark McDowall 2013-05-10 08:19:29 -07:00
parent 32431540c5
commit 3602822572
7 changed files with 20 additions and 9 deletions

View File

@ -365,7 +365,7 @@ public virtual SortBuilder<T> Where<TObj>(Expression<Func<TObj, bool>> filterExp
public virtual SortBuilder<T> Where(Expression<Func<T, bool>> filterExpression)
{
_whereBuilder = new WhereBuilder<T>(_db.Command, _dialect, filterExpression, _tables, false, true);
_whereBuilder = new WhereBuilder<T>(_db.Command, _dialect, filterExpression, _tables, _useAltName, true);
return SortBuilder;
}

View File

@ -217,8 +217,13 @@ public virtual string BuildQuery(bool useAltName)
}
string columnName = DataHelper.GetColumnName(sort.DeclaringType, sort.PropertyName, useAltName);
if (!_useAltName)
sb.Append(_dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName)));
else
sb.Append(_dialect.CreateToken(string.Format("{0}", columnName)));
if (sort.Direction == SortDirection.Desc)
sb.Append(" DESC");
}

View File

@ -182,7 +182,12 @@ protected string GetFullyQualifiedColumnName(MemberInfo member, Type declaringTy
}
string columnName = DataHelper.GetColumnName(declaringType, member.Name, _useAltName);
if (!_useAltName)
return _dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName));
else
return _dialect.CreateToken(string.Format("{0}", columnName));
}
else
{

View File

@ -23,6 +23,7 @@ public static class MappingExtensions
return mapBuilder.Table.MapTable(tableName)
.Columns
.AutoMapPropertiesWhere(IsMappableProperty)
.PrefixAltNames(String.Format("{0}_", typeof(T).Name))
.For(c => c.Id)
.SetPrimaryKey()
.SetReturnValue()

View File

@ -52,7 +52,8 @@ public static void Map()
Mapper.Entity<Season>().RegisterModel("Seasons");
Mapper.Entity<Episode>().RegisterModel("Episodes")
.Ignore(e => e.SeriesTitle);
.Ignore(e => e.SeriesTitle)
.Relationships.AutoMapICollectionOrComplexProperties();
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles");

View File

@ -75,14 +75,15 @@ public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec,
startingSeasonNumber = 0;
}
pagingSpec.Records = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
var pagingQuery = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Where(e => e.EpisodeFileId == 0)
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
.AndWhere(e => e.AirDate <= currentTime)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
.Skip(pagingSpec.PagingOffset())
.Take(pagingSpec.PageSize)
.ToList();
.Take(pagingSpec.PageSize);
pagingSpec.Records = pagingQuery.ToList();
//TODO: Use the same query for count and records
pagingSpec.TotalRecords = Query.Where(e => e.EpisodeFileId == 0 && e.SeasonNumber >= startingSeasonNumber && e.AirDate <= currentTime).Count();

View File

@ -99,8 +99,6 @@ public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec,
{
var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, includeSpecials);
episodeResult.Records = LinkSeriesToEpisodes(episodeResult.Records);
return episodeResult;
}