/// <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()); }
/// <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()); }
/// <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)); }
/// <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()); }
/// <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()); }
/// <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>()); }