// get a page of entities public IEnumerable <IEntitySlim> GetPagedResultsByQuery(IQuery <IUmbracoEntity> query, Guid objectType, long pageIndex, int pageSize, out long totalRecords, IQuery <IUmbracoEntity> filter, Ordering ordering) { var isContent = objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint; var isMedia = objectType == Constants.ObjectTypes.Media; var sql = GetBaseWhere(isContent, isMedia, false, x => { if (filter == null) { return; } foreach (var filterClause in filter.GetWhereClauses()) { x.Where(filterClause.Item1, filterClause.Item2); } }, objectType); ordering = ordering ?? Ordering.ByDefault(); var translator = new SqlTranslator <IUmbracoEntity>(sql, query); sql = translator.Translate(); sql = AddGroupBy(isContent, isMedia, sql, ordering.IsEmpty); if (!ordering.IsEmpty) { // apply ordering ApplyOrdering(ref sql, ordering); } //fixme - we should be able to do sql = sql.OrderBy(x => Alias(x.NodeId, "NodeId")); but we can't because the OrderBy extension don't support Alias currently //no matter what we always must have node id ordered at the end sql = ordering.Direction == Direction.Ascending ? sql.OrderBy("NodeId") : sql.OrderByDescending("NodeId"); var page = Database.Page <BaseDto>(pageIndex + 1, pageSize, sql); var dtos = page.Items; var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray(); if (isContent) { BuildVariants(entities.Cast <DocumentEntitySlim>()); } //fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media if (isMedia) { BuildProperties(entities, dtos); } totalRecords = page.TotalItems; return(entities); }
// get a page of entities public IEnumerable <IEntitySlim> GetPagedResultsByQuery(IQuery <IUmbracoEntity> query, Guid[] objectTypes, long pageIndex, int pageSize, out long totalRecords, IQuery <IUmbracoEntity>?filter, Ordering?ordering, Action <Sql <ISqlContext> >?sqlCustomization = null) { var isContent = objectTypes.Any(objectType => objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint); var isMedia = objectTypes.Any(objectType => objectType == Constants.ObjectTypes.Media); var isMember = objectTypes.Any(objectType => objectType == Constants.ObjectTypes.Member); Sql <ISqlContext> sql = GetBaseWhere(isContent, isMedia, isMember, false, s => { sqlCustomization?.Invoke(s); if (filter != null) { foreach (Tuple <string, object[]> filterClause in filter.GetWhereClauses()) { s.Where(filterClause.Item1, filterClause.Item2); } } }, objectTypes); ordering = ordering ?? Ordering.ByDefault(); var translator = new SqlTranslator <IUmbracoEntity>(sql, query); sql = translator.Translate(); sql = AddGroupBy(isContent, isMedia, isMember, sql, ordering.IsEmpty); if (!ordering.IsEmpty) { // apply ordering ApplyOrdering(ref sql, ordering); } // TODO: we should be able to do sql = sql.OrderBy(x => Alias(x.NodeId, "NodeId")); but we can't because the OrderBy extension don't support Alias currently // no matter what we always must have node id ordered at the end sql = ordering.Direction == Direction.Ascending ? sql.OrderBy("NodeId") : sql.OrderByDescending("NodeId"); // for content we must query for ContentEntityDto entities to produce the correct culture variant entity names var pageIndexToFetch = pageIndex + 1; IEnumerable <BaseDto> dtos; Page <GenericContentEntityDto>?page = Database.Page <GenericContentEntityDto>(pageIndexToFetch, pageSize, sql); dtos = page.Items; totalRecords = page.TotalItems; EntitySlim[] entities = dtos.Select(BuildEntity).ToArray(); BuildVariants(entities.OfType <DocumentEntitySlim>()); return(entities); }
// get a page of entities public IEnumerable <IEntitySlim> GetPagedResultsByQuery(IQuery <IUmbracoEntity> query, Guid objectType, long pageIndex, int pageSize, out long totalRecords, IQuery <IUmbracoEntity> filter, Ordering ordering) { var isContent = objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint; var isMedia = objectType == Constants.ObjectTypes.Media; var sql = GetBaseWhere(isContent, isMedia, false, x => { if (filter == null) { return; } foreach (var filterClause in filter.GetWhereClauses()) { x.Where(filterClause.Item1, filterClause.Item2); } }, objectType); ordering = ordering ?? Ordering.ByDefault(); var translator = new SqlTranslator <IUmbracoEntity>(sql, query); sql = translator.Translate(); sql = AddGroupBy(isContent, isMedia, sql, ordering.IsEmpty); if (!ordering.IsEmpty) { // apply ordering ApplyOrdering(ref sql, ordering); } // TODO: we should be able to do sql = sql.OrderBy(x => Alias(x.NodeId, "NodeId")); but we can't because the OrderBy extension don't support Alias currently //no matter what we always must have node id ordered at the end sql = ordering.Direction == Direction.Ascending ? sql.OrderBy("NodeId") : sql.OrderByDescending("NodeId"); // for content we must query for ContentEntityDto entities to produce the correct culture variant entity names var pageIndexToFetch = pageIndex + 1; IEnumerable <BaseDto> dtos; if (isContent) { var page = Database.Page <ContentEntityDto>(pageIndexToFetch, pageSize, sql); dtos = page.Items; totalRecords = page.TotalItems; } else if (isMedia) { var page = Database.Page <MediaEntityDto>(pageIndexToFetch, pageSize, sql); dtos = page.Items; totalRecords = page.TotalItems; } else { var page = Database.Page <BaseDto>(pageIndexToFetch, pageSize, sql); dtos = page.Items; totalRecords = page.TotalItems; } var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray(); if (isContent) { BuildVariants(entities.Cast <DocumentEntitySlim>()); } return(entities); }