예제 #1
0
        /// <summary>
        /// 查询数据库并将第一个结果集填充实体类型
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="query">要执行的查询</param>
        /// <param name="token">取消指示</param>
        /// <param name="converter">实体转换器</param>
        /// <returns>实体集</returns>
        public async static Task <T[]> ExecuteEntitiesAsync <T>(this IDbExecutable query, Func <DataRow, CancellationToken, Task <T> > converter, CancellationToken token = default(CancellationToken))
        {
            var data = await query.ExecuteDataTableAsync(token);

            List <T> result = new List <T>();

            foreach (var dataItem in data.GetRows())
            {
                var entity = await converter(dataItem, token);

                result.Add(entity);
            }

            return(result.ToArray());
        }
예제 #2
0
        /// <summary>
        /// 查询数据库并将第一个结果集填充实体类型
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="query">要执行的查询</param>
        /// <param name="token">取消指示</param>
        /// <param name="converter">实体转换器</param>
        /// <returns>实体集</returns>
        public async static Task <T[]> ExecuteEntitiesAsync <T>(this IDbExecutable query, Func <DataRow, T> converter, CancellationToken token = default(CancellationToken))
        {
            var data = await query.ExecuteDataTableAsync(token);

            return(data.GetRows().Select(dataItem => converter(dataItem)).ToArray());
        }
예제 #3
0
        /// <summary>
        /// 异步执行查询并将第一个结果集填充动态对象列表
        /// </summary>
        /// <param name="query">要执行的查询</param>
        /// <param name="token">取消指示</param>
        /// <returns>查询结果</returns>
        public static async Task <dynamic[]> ExecuteDynamicsAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken))
        {
            var data = await query.ExecuteDataTableAsync(token);

            return(ToDynamics(data));
        }
예제 #4
0
 /// <summary>
 /// 异步执行查询并将第一行数据数据转换为 DataRowView 返回
 /// </summary>
 /// <param name="query">要执行的查询</param>
 /// <returns>转换为 DataRowView 的数据集合</returns>
 public async static Task <DataRowView> ExecuteFirstDataRowViewAsync(this IDbExecutable query)
 {
     return((await query.ExecuteDataTableAsync()).GetRowViews().FirstOrDefault());
 }
예제 #5
0
 /// <summary>
 /// 异步执行查询并将数据转换为 DataRowView 集合返回
 /// </summary>
 /// <param name="query">要执行的查询</param>
 /// <returns>转换为 DataRowView 的数据集合</returns>
 public async static Task <IEnumerable <DataRowView> > ExecuteDataRowViewsAsync(this IDbExecutable query)
 {
     return((await query.ExecuteDataTableAsync()).GetRowViews());
 }
예제 #6
0
 /// <summary>
 /// 异步执行查询并返回第一列数据
 /// </summary>
 /// <typeparam name="T">列类型</typeparam>
 /// <param name="query">要执行的查询</param>
 /// <returns>第一列的数据</returns>
 public async static Task <T[]> ExecuteFirstColumnAsync <T>(this IDbExecutable query)
 {
     return((await query.ExecuteDataTableAsync()).Column <T>());
 }