public override void ModifyQueryDescription(QueryDescriptionBuilder queryDescription, Type resultType)
        {
            var pageNumberExpr = FirstParameter as ConstantExpression;
            var pageSizeExpr   = PageSize as ConstantExpression;

            if (pageNumberExpr == null || pageSizeExpr == null)
            {
                return;
            }

            int?pageNumber = pageNumberExpr.Value as int?;
            int?pageSize   = pageSizeExpr.Value as int?;

            if (pageNumber.HasValue && pageSize.HasValue)
            {
                queryDescription.AddSkipResultFilter(resultType, pageSize.Value * (pageNumber.Value - 1));
                queryDescription.AddTakeResultFilter(resultType, pageSize.Value);
            }
        }
Exemple #2
0
        /// <summary>
        /// Visits the result operator.
        /// </summary>
        /// <param name="resultOperator">The result operator.</param>
        /// <param name="queryModel">The query model.</param>
        /// <param name="index">The index.</param>
        /// <remarks></remarks>
        public override void VisitResultOperator(ResultOperatorBase resultOperator, Remotion.Linq.QueryModel queryModel, int index)
        {
            if (typeof(CountResultOperator).IsAssignableFrom(resultOperator.GetType()))
            {
                //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.Count, 0);
                _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.Count, 0);
            }

            if (typeof(SingleResultOperator).IsAssignableFrom(resultOperator.GetType()))
            {
                var op     = resultOperator as SingleResultOperator;
                var filter = op.ReturnDefaultWhenEmpty ? ResultFilterType.SingleOrDefault : ResultFilterType.Single;
                //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, filter, 0);
                _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, filter, 0);
            }

            if (typeof(TakeResultOperator).IsAssignableFrom(resultOperator.GetType()))
            {
                var firstResultOperator = resultOperator as TakeResultOperator;
                var countExpression     = firstResultOperator.Count as ConstantExpression;
                var count = Convert.ToInt32(countExpression.Value);
                //_queryDescription.SetTakeResultFilter(queryModel.MainFromClause.ItemType, count);
                _queryDescription.AddTakeResultFilter(queryModel.MainFromClause.ItemType, count);
            }

            var skipResultOp = resultOperator as SkipResultOperator;

            if (skipResultOp != null)
            {
                var countExpression = skipResultOp.Count as ConstantExpression;
                var count           = Convert.ToInt32(countExpression.Value);
                //_queryDescription.SetSkipResultFilter(queryModel.MainFromClause.ItemType, count);
                _queryDescription.AddSkipResultFilter(queryModel.MainFromClause.ItemType, count);
            }

            if (resultOperator is AnyResultOperator)
            {
                //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.Any, 0);
                _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.Any, 0);
            }

            var allResultOp = resultOperator as AllResultOperator;

            if (allResultOp != null)
            {
                var criteriaExpression = this.GetCriteriaExpression(queryModel, allResultOp.Predicate);
                _queryDescription.SetCriteria(criteriaExpression);
                //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.All, 0);
                _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.All, 0);
            }

            var firstResultOp = resultOperator as FirstResultOperator;

            if (firstResultOp != null)
            {
                //this._queryDescription.SetResultFilterClause(
                //    queryModel.MainFromClause.ItemType,
                //    firstResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.FirstOrDefault : ResultFilterType.First,
                //    0);

                this._queryDescription.AddResultFilter(
                    queryModel.MainFromClause.ItemType,
                    firstResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.FirstOrDefault : ResultFilterType.First,
                    0);
            }

            var lastResultOp = resultOperator as LastResultOperator;

            if (lastResultOp != null)
            {
                this._queryDescription.AddResultFilter(
                    queryModel.MainFromClause.ItemType,
                    lastResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.LastOrDefault : ResultFilterType.Last,
                    0);
            }

            base.VisitResultOperator(resultOperator, queryModel, index);
        }