Ejemplo n.º 1
0
        public async Task <PageList <T> > PageListAsync(int pageIndex, int pageSize)
        {
            SqlProvider.FormatToPageList(GetSourceType(), pageIndex, pageSize, this.FieldAnyExpression);
            SetSql();
            try {
                var ps = typeof(T).GetJsonColumnProperty();

                var Reader = await DbCon.ExecuteReaderAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction);

                var pageTotal = 0;
                if (Reader.Read())
                {
                    pageTotal = Reader.GetInt32(0);
                }
                Reader.NextResult();
                var lrst = ProcessPageList(Reader, ps);
                Reader.Close();
                return(new PageList <T>(pageIndex, pageSize, pageTotal, lrst));
            }
            catch (Exception e)
            {
                CallEvent(SqlProvider.SqlString, SqlProvider.Params, e.Message);
                if (Throws)
                {
                    throw new Exception($"{e.Message} sql:{SqlProvider.SqlString} params:{SqlProvider.Params}", e);
                }
                else
                {
                    return(new PageList <T>(0, 0, 0, new List <T>()));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <PageList <T> > PageListAsync(int pageIndex, int pageSize)
        {
            SqlProvider.FormatToPageList(GetSourceType(), pageIndex, pageSize, this.FieldAnyExpression);
            SetSql();
            try {
                var ps = typeof(T).GetJsonColumnProperty();
                if (ps.Length > 0 && HasSerializer)
                {
                    var Reader = await DbCon.ExecuteReaderAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction);

                    var pageTotal = 0;
                    if (Reader.Read())
                    {
                        pageTotal = Reader.GetInt32(0);
                    }
                    Reader.NextResult();
                    var      Parser = Reader.GetRowParser(typeof(T));
                    List <T> lrst   = new List <T>();
                    while (Reader.Read())
                    {
                        object rst = Parser(Reader);
                        foreach (var p in ps)
                        {
                            var col = Reader.GetOrdinal($"{p.Name}{ResolveExpression.JsonColumnNameSuffix}");
                            var s   = Reader.GetString(col);
                            var pv  = Deserializer(s, p.PropertyType);
                            p.SetValue(rst, pv);
                        }
                        lrst.Add((T)rst);
                    }
                    Reader.Close();
                    return(new PageList <T>(pageIndex, pageSize, pageTotal, lrst));
                }
                else
                {
                    using (var queryResult = await DbCon.QueryMultipleAsync(SqlProvider.SqlString, SqlProvider.Params, DbTransaction))
                    {
                        var pageTotal = queryResult.ReadFirst <int>();

                        var itemList = await PageListItemsAsync(queryResult);

                        return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList));
                    }
                }
            }
            catch (Exception e)
            {
                CallEvent(SqlProvider.SqlString, SqlProvider.Params, e.Message);
                if (Throws)
                {
                    throw new Exception($"{e.Message} sql:{SqlProvider.SqlString} params:{SqlProvider.Params}", e);
                }
                else
                {
                    return(new PageList <T>(0, 0, 0, new List <T>()));
                }
            }
        }
Ejemplo n.º 3
0
        public PageList <T> PageList(int pageIndex, int pageSize)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction);

            //查询数据
            SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
            var itemList = DbCon.Query_1 <T>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction);

            return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 4
0
        public async Task <PageList <TReturn> > PageListAsync <TReturn>(int pageIndex, int pageSize, bool where, Expression <Func <T, TReturn> > trueSelect, Expression <Func <T, TReturn> > falseSelect)
        {
            if (where)
            {
                SqlProvider.Context.Set.SelectExpression = trueSelect;
            }
            else
            {
                SqlProvider.Context.Set.SelectExpression = falseSelect;
            }
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = await DbCon.QuerySinglesAsync <int>(SqlProvider, DbTransaction);

            //查询数据
            List <TReturn> itemList;

            SqlProvider.Params.Clear();
            SqlProvider.ProviderOption.MappingList.Clear();
            if (pageTotal != 0)
            {
                SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
                itemList = await DbCon.Query_1Async <TReturn>(SqlProvider, DbTransaction);
            }
            else
            {
                itemList = new List <TReturn>();
            }
            return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 5
0
 public PageList <T> PageList(int pageIndex, int pageSize)
 {
     SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
     using (var queryResult = DbCon.QueryMultiples <T>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction))
     {
         //oracle不支持返回多条结果集
         var pageTotal = 0;
         if (SqlProvider.IsSelectCount)
         {
             SqlProvider.FormatCount();
             pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction);
         }
         else
         {
             pageTotal = queryResult.ReadFirst <int>();
         }
         var itemList = queryResult.Read <T>().ToList();
         return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList));
     }
 }
Ejemplo n.º 6
0
        public PageList <TSource> PageList <TSource>(int pageIndex, int pageSize)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction);

            SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
            //查询数据
            var itemList = DbCon.Query_1 <TSource>(SqlProvider, DbTransaction);

            return(new PageList <TSource>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 7
0
        public PageList <T> PageList(int pageIndex, int pageSize)
        {
            SqlProvider.FormatToPageList <T>(pageIndex, pageSize);

            using (var queryResult = DbCon.QueryMultiple(SqlProvider.SqlString, SqlProvider.Params, DbTransaction))
            {
                var pageTotal = queryResult.ReadFirst <int>();

                var itemList = queryResult.Read <T>().ToList();

                return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList));
            }
        }
Ejemplo n.º 8
0
        public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, Expression <Func <T, TReturn> > select)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction);

            //查询数据
            SqlProvider.Context.Set.SelectExpression = select;
            SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
            var itemList = DbCon.Query_1 <TReturn>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction);

            return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 9
0
        public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, bool where, Expression <Func <T, TReturn> > trueSelect, Expression <Func <T, TReturn> > falseSelect)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction);

            if (where)
            {
                SqlProvider.Context.Set.SelectExpression = trueSelect;
            }
            else
            {
                SqlProvider.Context.Set.SelectExpression = falseSelect;
            }
            SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
            var itemList = DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction);

            return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 10
0
        public PageList <TSource> PageList <TSource>(int pageIndex, int pageSize)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction);
            //查询数据
            List <TSource> itemList;

            SqlProvider.Clear();
            if (pageTotal != 0)
            {
                SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
                itemList = DbCon.Query_1 <TSource>(SqlProvider, DbTransaction);
            }
            else
            {
                itemList = new List <TSource>();
            }
            return(new PageList <TSource>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 11
0
        public async Task <PageList <T> > PageListAsync(int pageIndex, int pageSize)
        {
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = await DbCon.QuerySinglesAsync <int>(SqlProvider, DbTransaction);

            //查询数据
            List <T> itemList;

            SqlProvider.Clear();
            if (pageTotal != 0)
            {
                SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
                itemList = await DbCon.Query_1Async <T>(SqlProvider, DbTransaction);
            }
            else
            {
                itemList = new List <T>();
            }
            return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList));
        }
Ejemplo n.º 12
0
        public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, Expression <Func <T, TReturn> > select)
        {
            SqlProvider.Context.Set.SelectExpression = select;
            //查询总行数
            SqlProvider.FormatCount();
            var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction);
            //查询数据
            List <TReturn> itemList;

            SqlProvider.Clear();
            if (pageTotal != 0)
            {
                SqlProvider.FormatToPageList <T>(pageIndex, pageSize);
                itemList = DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction);
            }
            else
            {
                itemList = new List <TReturn>();
            }
            return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList));
        }