示例#1
0
        /// <summary>
        /// Get the page size.
        /// </summary>
        /// <param name="responseValue">The response value.</param>
        /// <param name="singleResultCollection">The content as SingleResult.Queryable.</param>
        /// <param name="actionDescriptor">The action context, i.e. action and controller name.</param>
        /// <param name="modelFunction">A function to get the model.</param>
        /// <param name="path">The OData path.</param>
        /// <param name="createErrorAction">A function used to generate error response.</param>
        private void GetModelBoundPageSize(
            object responseValue,
            IQueryable singleResultCollection,
            IWebApiActionDescriptor actionDescriptor,
            Func <Type, IEdmModel> modelFunction,
            ODataPath path,
            Action <HttpStatusCode, string, Exception> createErrorAction)
        {
            ODataQueryContext queryContext = null;

            try
            {
                queryContext = GetODataQueryContext(responseValue, singleResultCollection, actionDescriptor, modelFunction, path);
            }
            catch (InvalidOperationException e)
            {
                createErrorAction(
                    HttpStatusCode.BadRequest,
                    Error.Format(SRResources.UriQueryStringInvalid, e.Message),
                    e);
                return;
            }

            ModelBoundQuerySettings querySettings = EdmLibHelpers.GetModelBoundQuerySettings(queryContext.TargetProperty,
                                                                                             queryContext.TargetStructuredType,
                                                                                             queryContext.Model);

            if (querySettings != null && querySettings.PageSize.HasValue)
            {
                _querySettings.ModelBoundPageSize = querySettings.PageSize;
            }
        }