Exemplo n.º 1
0
        public virtual object ApplyQueryOptions(object value, HttpRequest request, ActionDescriptor actionDescriptor, AssembliesResolver assembliesResolver)
        {
            var elementClrType = value is IEnumerable
                                ? TypeHelper.GetImplementedIEnumerableType(value.GetType())
                                : value.GetType();

            var model = request.ODataProperties().Model;

            if (model == null)
            {
                throw Error.InvalidOperation(SRResources.QueryGetModelMustNotReturnNull);
            }

            var queryContext = new ODataQueryContext(
                model,
                elementClrType,
                assembliesResolver,
                request.ODataProperties().Path
                );

            var queryOptions = new ODataQueryOptions(queryContext, request, assembliesResolver);

            var enumerable = value as IEnumerable;

            if (enumerable == null)
            {
                // response is single entity.
                return(value);
            }

            // response is a collection.
            var query = (value as IQueryable) ?? enumerable.AsQueryable();

            query = queryOptions.ApplyTo(query,
                                         new ODataQuerySettings
            {
                // TODO: If we are using SQL, set this to false
                // otherwise if it is entities in code then
                // set it to true
                HandleNullPropagation =
                    //HandleNullPropagationOption.True
                    HandleNullPropagationOptionHelper.GetDefaultHandleNullPropagationOption(query),
                PageSize = actionDescriptor.PageSize(),
                SearchDerivedTypeWhenAutoExpand = true
            },
                                         AllowedQueryOptions.None);
            // Determine if this result should be a single entity

            if (ODataCountMediaTypeMapping.IsCountRequest(request))
            {
                long?count = request.ODataProperties().TotalCount;

                if (count.HasValue)
                {
                    // Return the count value if it is a $count request.
                    return(count.Value);
                }
            }
            return(query);
        }
Exemplo n.º 2
0
        private int?ResolvePageSize(ODataQuerySettings querySettings, ActionDescriptor actionDescriptor)
        {
            // if (!_pageSizeChecked)
            //  {
            //   _pageSizeChecked = true;
            var queryPageSize  = querySettings.PageSize;
            var actionPageSize = actionDescriptor.PageSize();

            _pageSize = actionPageSize.IsSet ? actionPageSize.Size : queryPageSize;
            //    }
            return(_pageSize);
        }
Exemplo n.º 3
0