示例#1
0
        public async Task <PagingResult <T> > ToPageListAsync(int pageIndex, int pageSize)
        {
            var fields = GetFields();
            var from   = GetFrom();

            var sqlBuilder = new SqlServerBuilder();
            var sql        = sqlBuilder.PagingSelect(from, fields, _where, _orderBy, pageIndex, pageSize);

            var command = new SqlCommand(sql);

            command.Parameters.AddRange(_parameters.Parameters);
            var param = new SqlParameter("@RecordCount", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };

            command.Parameters.Add(param);

            var result = new PagingResult <T>();

            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                command.Connection = conn;
                using (var sdr = await command.ExecuteReaderAsync())
                {
                    var handler = new SqlDataReaderConverter <T>(_includeProperties.Select(p => p.PropertyName).ToArray());
                    result.Items = handler.ConvertToEntityList(sdr);
                }
            }

            result.RecordCount = (int)param.Value;
            return(result);
        }