示例#1
0
        private IEnumerable <IUmbracoEntity> PerformGetAll(Guid objectTypeId, Action <Sql> filter = null)
        {
            var isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
            var isMedia   = objectTypeId == Constants.ObjectTypes.MediaGuid;
            var sql       = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, filter);

            var factory = new UmbracoEntityFactory();

            if (isMedia)
            {
                //for now treat media differently and include all property data too
                var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>(
                    new UmbracoEntityRelator().Map, sql);
                return(entities);
            }
            else
            {
                //query = read forward data reader, do not load everything into mem
                var dtos       = _work.Database.Query <dynamic>(sql);
                var collection = new EntityDefinitionCollection();
                foreach (var dto in dtos)
                {
                    collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false));
                }
                return(collection.Select(x => x.BuildFromDynamic()).ToList());
            }
        }
示例#2
0
        public virtual IUmbracoEntity Get(int id, Guid objectTypeId)
        {
            bool isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
            bool isMedia   = objectTypeId == Constants.ObjectTypes.MediaGuid;

            var sql = GetFullSqlForEntityType(id, isContent, isMedia, objectTypeId);

            var factory = new UmbracoEntityFactory();

            if (isMedia)
            {
                //for now treat media differently and include all property data too
                var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>(
                    new UmbracoEntityRelator().Map, sql);

                return(entities.FirstOrDefault());
            }
            else
            {
                //query = read forward data reader, do not load everything into mem
                var dtos       = _work.Database.Query <dynamic>(sql);
                var collection = new EntityDefinitionCollection();
                foreach (var dto in dtos)
                {
                    collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false));
                }
                var found = collection.FirstOrDefault();
                return(found != null?found.BuildFromDynamic() : null);
            }
        }
        private IEnumerable <IUmbracoEntity> GetByQueryInternal(Sql entitySql, bool isContent, bool isMedia)
        {
            var factory = new UmbracoEntityFactory();

            //use dynamic so that we can get ALL properties from the SQL so we can chuck that data into our AdditionalData
            var finalSql = entitySql.Append(GetGroupBy(isContent, isMedia));

            //query = read forward data reader, do not load everything into mem
            var dtos       = UnitOfWork.Database.Query <dynamic>(finalSql);
            var collection = new EntityDefinitionCollection();

            foreach (var dto in dtos)
            {
                collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, isMedia));
            }
            return(collection.Select(x => x.BuildFromDynamic()).ToList());
        }
示例#4
0
        public virtual IEnumerable <IUmbracoEntity> GetByQuery(IQuery <IUmbracoEntity> query, Guid objectTypeId)
        {
            bool isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
            bool isMedia   = objectTypeId == Constants.ObjectTypes.MediaGuid;

            var sqlClause = GetBaseWhere(GetBase, isContent, isMedia, null, objectTypeId);

            var translator = new SqlTranslator <IUmbracoEntity>(sqlClause, query);
            var entitySql  = translator.Translate();

            var factory = new UmbracoEntityFactory();

            if (isMedia)
            {
                var wheres = query.GetWhereClauses().ToArray();

                var mediaSql = GetFullSqlForMedia(entitySql.Append(GetGroupBy(isContent, true, false)), sql =>
                {
                    //adds the additional filters
                    foreach (var whereClause in wheres)
                    {
                        sql.Where(whereClause.Item1, whereClause.Item2);
                    }
                });

                //for now treat media differently and include all property data too
                var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>(
                    new UmbracoEntityRelator().Map, mediaSql);
                return(entities);
            }
            else
            {
                //use dynamic so that we can get ALL properties from the SQL so we can chuck that data into our AdditionalData
                var finalSql = entitySql.Append(GetGroupBy(isContent, false));

                //query = read forward data reader, do not load everything into mem
                var dtos       = _work.Database.Query <dynamic>(finalSql);
                var collection = new EntityDefinitionCollection();
                foreach (var dto in dtos)
                {
                    collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false));
                }
                return(collection.Select(x => x.BuildFromDynamic()).ToList());
            }
        }
        private IEnumerable <IUmbracoEntity> PerformGetAll(Guid objectTypeId, Action <Sql> filter = null)
        {
            var isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
            var isMedia   = objectTypeId == Constants.ObjectTypes.MediaGuid;
            var sql       = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, filter);

            var factory = new UmbracoEntityFactory();

            //query = read forward data reader, do not load everything into mem
            var dtos       = UnitOfWork.Database.Query <dynamic>(sql);
            var collection = new EntityDefinitionCollection();

            foreach (var dto in dtos)
            {
                collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, isMedia));
            }
            return(collection.Select(x => x.BuildFromDynamic()).ToList());
        }
        public virtual IUmbracoEntity Get(int id, Guid objectTypeId)
        {
            bool isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
            bool isMedia   = objectTypeId == Constants.ObjectTypes.MediaGuid;

            var sql = GetFullSqlForEntityType(id, isContent, isMedia, objectTypeId);

            var factory = new UmbracoEntityFactory();

            //query = read forward data reader, do not load everything into mem
            var dtos       = UnitOfWork.Database.Query <dynamic>(sql);
            var collection = new EntityDefinitionCollection();

            foreach (var dto in dtos)
            {
                collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, false));
            }
            var found = collection.FirstOrDefault();

            return(found != null?found.BuildFromDynamic() : null);
        }