Ejemplo n.º 1
0
        /// <summary>
        /// async Paging Datas by Database
        /// </summary>
        /// <param name="pageIndex">Current Index</param>
        /// <param name="pageSize">Size of per Page</param>
        /// <param name="fixedSql">The Sql which in the Front ( ex.  CTE Query begin with the Keyword "WITH" ) </param>
        /// <param name="selectSql">The Sql which begin with Keyword "SELECT" </param>
        /// <param name="paramValues">Parameters</param>
        /// <param name="connectionAliasName">the Alias Name of Connection (if not pass name,it will use the DEFAULT name instead.)</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        public static async Task <PagingResult> PagingAsDatatableAsync(int pageIndex, int pageSize,
                                                                       string fixedSql, string selectSql, SqlParameter[] paramValues,
                                                                       string connectionAliasName = MicroDBHelper.ALIAS_NAME_DEFAULT, CommandType commandType = CommandType.Text
                                                                       )
        {
            ExecuteAsyncDelegate action = async(m_Sql, m_paramValues, m_commandType) =>
            {
                return(await MicroDBHelper.ExecuteDataTableAsync(m_Sql, m_paramValues, connectionAliasName, m_commandType));
            };

            var ret = await AdapterFactory.CreateAdapter(connectionAliasName).DetailPagingAsync(action, pageIndex, pageSize, fixedSql, selectSql, paramValues, commandType);

            return(new PagingResult(ret.querydt, pageIndex, pageSize, ret.totalCount));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// async Paging Datas by Database <para />
        /// (need to reference: MicroDBHelperExpansionPack.EntityConversion )
        /// </summary>
        /// <typeparam name="T">Target Type</typeparam>
        /// <param name="pageIndex">Current Index</param>
        /// <param name="pageSize">Size of per Page</param>
        /// <param name="fixedSql">The Sql which in the Front ( ex.  CTE Query begin with the Keyword "WITH" ) </param>
        /// <param name="selectSql">The Sql which begin with Keyword "SELECT" </param>
        /// <param name="paramValues">Parameters</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        public static async Task <PagingResult <T> > PagingAsEntityAsync <T>(int pageIndex, int pageSize,
                                                                             string fixedSql, string selectSql, SqlParameter[] paramValues,
                                                                             MicroDBTransaction transaction, CommandType commandType = CommandType.Text
                                                                             )
            where T : class
        {
            ExecuteAsyncDelegate action = async(m_Sql, m_paramValues, m_commandType) =>
            {
                return(await MicroDBHelper.ExecuteDataTableAsync(m_Sql, m_paramValues, transaction, m_commandType));
            };

            var ret = await AdapterFactory.CreateAdapter(transaction.ConnectionAliasName).DetailPagingAsync(action, pageIndex, pageSize, fixedSql, selectSql, paramValues, commandType);

            return(new PagingResult <T>(EntityConvert.ConvertToList <T>(ret.querydt), pageIndex, pageSize, ret.totalCount));
        }
        /// <summary>
        /// Detail to PagingAsync
        /// </summary>
        public async Task <DetailPagingRet> DetailPagingAsync(ExecuteAsyncDelegate executeAction,
                                                              int pageIndex, int pageSize,
                                                              string fixedSql, string selectSql, SqlParameter[] paramValues,
                                                              CommandType commandType = CommandType.Text
                                                              )
        {
            //##0 init
            string SELECTSQL, orderBodyString, SELECTWithoutOrder, fromBodyString, FINALSQL;
            int    totalCount = 0;
            var    paras      = new List <SqlParameter>();

            //##1 Check
            DealHelper.DetailPagingHelper_Prepare(selectSql, out SELECTSQL);

            try
            {
                DealHelper.DetailPagingHelper_SplitStrings(SELECTSQL, out orderBodyString, out SELECTWithoutOrder, out fromBodyString);

                string sqlCount;
                DetailPagingHelper_SqlCount(fixedSql, SELECTSQL, SELECTWithoutOrder, fromBodyString, orderBodyString, out sqlCount);

                //##2 get record total and begin to page
                DataTable countDt = await executeAction(sqlCount, paramValues, commandType);

                DetailPagingHelper_SqlPage(countDt, paramValues, orderBodyString, SELECTWithoutOrder, fixedSql,
                                           pageIndex, pageSize,
                                           ref SELECTSQL, ref paras,
                                           out totalCount, out FINALSQL);


                //##3 exec sql expreession and return result
                DataTable querydt = await executeAction(FINALSQL, paras.ToArray(), commandType);

                return(DetailPagingHelper_returnResult(querydt, totalCount));
            }
            catch (SqlException ex)
            {
                throw DealHelper.DetailPagingHelper_CatchException_SqlException(ex, fixedSql, SELECTSQL);
            }
            catch (Exception ex)
            {
                throw DealHelper.DetailPagingHelper_CatchException_CommonException(ex, fixedSql, SELECTSQL, totalCount);
            }
        }
 public MongoAsyncCursorSource(IQueryable <TElement> queryable, IQueryProvider realQueryProvider, ExecuteAsyncDelegate <IAsyncCursor <TElement> > executeAsyncFunction)
 {
     _queryable            = queryable;
     _realQueryProvider    = realQueryProvider;
     _executeAsyncFunction = executeAsyncFunction;
 }