Exemplo n.º 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 IAsyncDbExecutableQuery query, CancellationToken token, Func <DataRow, CancellationToken, Task <T> > converter)
        {
            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());
        }
Exemplo n.º 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 IAsyncDbExecutableQuery query, CancellationToken token, IEntityConverter <T> converter) where T : new()
        {
            var data = await query.ExecuteDataTableAsync(token);

            return(data.GetRows().Select(dataItem => dataItem.ToEntity <T>(converter)).ToArray());
        }
Exemplo n.º 3
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 IAsyncDbExecutableQuery query, CancellationToken token, Func <DataRow, T> converter)
        {
            var data = await query.ExecuteDataTableAsync(token);

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

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