1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 01:37:07 +00: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 @@ namespace Marr.Data.QGen
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 @@ namespace Marr.Data.QGen
}
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 @@ namespace Marr.Data.QGen
}
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 @@ namespace NzbDrone.Core.Datastore
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 @@ namespace NzbDrone.Core.Datastore
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 @@ namespace NzbDrone.Core.Tv
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 @@ namespace NzbDrone.Core.Tv
{
var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, includeSpecials);
episodeResult.Records = LinkSeriesToEpisodes(episodeResult.Records);
return episodeResult;
}