Beispiel #1
0
        public async Task <RestItemData> GetDataAsync(IEnumerable <string> fieldNames)
        {
            var fieldAuth = new FieldAuthChecker <TItem>(_context.Fields, _context.AuthorizationChecker, _item);
            IEnumerable <string> fields = fieldAuth.GetOrEnsureFields(fieldNames, 0);

            var selector      = new QueryableFieldSelector <TItem>(_context.Fields, fields);
            var loadedObjects = await selector.SelectFieldsOnlyAsync(_item.Query, _context.Repository.ForEachAsync);

            RestItemData loadedObject = ItemQueryHelper.SingleOrThrow(loadedObjects);

            return(loadedObject);
        }
        /// <summary>
        /// Loads a single scalar field reader from a single <see cref="itemQuery"/>.
        /// </summary>
        public static async Task <object> LoadScalarValueAsync <TItem>([NotNull] IFieldReader <TItem> reader, IQueryableSingle <TItem> itemQuery, ForEachAsyncDelegate <object> forEachAsync)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            ParameterExpression itemPram         = Expression.Parameter(typeof(TItem), "itm");
            Expression          selectExpression = reader.GetSelectExpression(itemPram);

            IQueryable selectScalarOnlyQuery = ExpressionTreeHelpers.GetSelectExpressionQuery(itemQuery, itemPram, selectExpression);
            object     loadedValue           = await ItemQueryHelper.SingleOrCreateAsync(selectScalarOnlyQuery, forEachAsync, () => throw new ParentItemNotFoundException());

            if (reader.Replacer != null)
            {
                await reader.Replacer.LoadAsync(itemQuery);

                return(reader.Replacer.GetReplacement(loadedValue));
            }

            return(loadedValue);
        }