예제 #1
0
파일: DMQuery.cs 프로젝트: szlixun/chutian
        public virtual PageList <TResult> ToPageList(int pageIndex, int pageSize)
        {
            PageList <TResult> pl = new PageList <TResult>();

            using (var translator = DMObjectContainer.GetTSQLTranslator())
            {
                Expression <Func <T1, int> > count = (p) => p.DMCount("1");
                using (TranResult countTr = translator.CreateAggregateTSQL <T1>(where.LambdaExpression, count, group.LambdaExpression, join.LambdaExpression))
                {
                    using (ATSqlCommand countCmd = new ATSqlCommand())
                    {
                        countCmd.SetCmdText(countTr.CmdText);
                        countCmd.SetParameters(countTr.Parameter.ToArray());
                        countCmd.SetConnectionString(base.ConnectionString);
                        if (group.LambdaExpression != null)
                        {
                            pl.Total = countCmd.ToDataTable().Rows.Count;
                        }
                        else
                        {
                            pl.Total = countCmd.ExecuteScalar <int>();
                        }
                        pl.Index = pageIndex;
                        pl.Size  = pageSize;
                    }
                }

                if (pl.Total != 0)
                {
                    using (TranResult tr = translator.CreateSelectPageListTSQL <T1>(pageIndex, pageSize, where.LambdaExpression, order.LambdaExpression, select.LambdaExpression, group.LambdaExpression, join.LambdaExpression))
                    {
                        using (ATSqlCommand cmd = new ATSqlCommand())
                        {
                            cmd.SetCmdText(tr.CmdText);
                            cmd.SetParameters(tr.Parameter.ToArray());
                            cmd.SetConnectionString(base.ConnectionString);
                            pl.List = cmd.ToList <TResult>();
                        }
                    }
                }
                return(pl);
            }
        }