Exemplo n.º 1
0
        public virtual PagingModel GetCriteriaByPage(Expression filterExpression = null, PagingInfo pagingInfo = null,
                                                     bool includeParameters      = true)
        {
            if (pagingInfo.IsNull())
            {
                pagingInfo = new PagingInfo
                {
                    PageNumber  = 1,
                    RowsPerPage = 50,
                    SortColumn  = "Id",
                    SortOrder   = "DESC"
                };
            }

            PagingModel pagingModel    = null;
            var         models         = new List <object>();
            var         castExpression = filterExpression as Expression <Func <TModel, bool> >;

            var queryInfo = QueryBuilder.BuildPagedQuery(pagingInfo, castExpression,
                                                         includeParameters: includeParameters);

            Database.CreateCommandText(queryInfo.Query, QueryType.Text)
            .WithParameters(queryInfo.Parameters)
            .ExecuteMultiple(r =>
            {
                if (pagingModel.IsNull())
                {
                    pagingModel = PagingModelBuilder.Build(r);
                }

                models.Add(Builder.Build <TModel>(r));

                return(pagingModel);
            });

            if (pagingModel.IsNotNull())
            {
                pagingModel.Items       = models;
                pagingModel.CurrentPage = pagingInfo.PageNumber;
                pagingModel.RowsPerPage = pagingInfo.RowsPerPage;
            }

            return(pagingModel);
        }
Exemplo n.º 2
0
        public QueryInfo BuildPagedQuery <TValue>(PagingInfo pagingInfo, Expression <Func <TValue, bool> > predicate = null, bool canDirtyRead = false,
                                                  bool includeParameters = true, IEnumerable <string> desiredFields = null, string tableName = null) where TValue : class
        {
            if (pagingInfo.IsNull())
            {
                return(BuildSelectQuery(predicate, canDirtyRead, includeParameters, desiredFields, tableName));
            }

            dynamic parameters = new ExpandoObject();

            parameters.PagingInfo        = pagingInfo;
            parameters.DesiredFields     = desiredFields;
            parameters.Predicate         = predicate;
            parameters.CanDirtyRead      = canDirtyRead;
            parameters.IncludeParameters = includeParameters;

            var strategy = _builderStrategyFactory.GetBuilderStrategy(QueryKind.PagedSingle);
            var info     = strategy.BuildQuery <TValue>(parameters);

            return(info);
        }