/// <summary> /// 异步执行没有结果的查询 /// </summary> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询所影响的行数</returns> public static async Task <int> ExecuteNonQueryAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { using (var context = await query.ExecuteAsync(token)) { return(context.RecordsAffected); } }
/// <summary> /// 执行没有结果的查询 /// </summary> /// <param name="query">要执行的查询对象</param> /// <returns>查询所影响的行数</returns> public static int ExecuteNonQuery(this IDbExecutable query) { using (var context = query.Execute()) { return(context.RecordsAffected); } }
/// <summary> /// 执行查询并将第一个结果集包装成 DataTable 返回 /// </summary> /// <param name="query">要执行的查询对象</param> /// <returns>查询结果</returns> public static DataTable ExecuteDataTable(this IDbExecutable query) { using (var context = query.Execute()) { return(context.LoadDataTable(0, 0)); } }
/// <summary> /// 异步执行查询并将第一个结果集包装成 DataTable 返回 /// </summary> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询结果</returns> public static async Task <DataTable> ExecuteDataTableAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { using (var context = await query.ExecuteAsync(token)) { return(await context.LoadDataTableAsync(0, 0, token)); } }
/// <summary> /// 执行查询并将所有结果集包装成 DataTable 返回 /// </summary> /// <param name="query">要执行的查询对象</param> /// <returns>查询结果</returns> public static DataTable[] ExecuteAllDataTables(this IDbExecutable query) { List <DataTable> dataTables = new List <DataTable>(); using (var context = query.Execute()) { do { dataTables.Add(context.LoadDataTable(0, 0)); } while (context.NextResult()); } return(dataTables.ToArray()); }
/// <summary> /// 异步执行查询并将所有结果集包装成 DataTable 返回 /// </summary> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询结果</returns> public static async Task <DataTable[]> ExecuteAllDataTablesAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { List <DataTable> dataTables = new List <DataTable>(); using (var context = await query.ExecuteAsync(token)) { do { dataTables.Add(context.LoadDataTable(0, 0)); } while (await context.NextResultAsync()); } return(dataTables.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, 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> /// <param name="query">要执行的查询对象</param> /// <returns>查询结果</returns> public static object ExecuteScalar(this IDbExecutable query) { using (var context = query.Execute()) { var record = context.ReadRecord(); if (record != null && record.FieldCount > 0) { return(record[0]); } else { return(null); } } }
/// <summary> /// 异步执行查询并返回首行首列 /// </summary> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询结果</returns> public static async Task <object> ExecuteScalarAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { using (var context = await query.ExecuteAsync(token)) { var record = await context.ReadRecordAsync(); if (record != null && record.FieldCount > 0) { return(record[0]); } else { return(null); } } }
/// <summary> /// 异步执行查询并返回首行 /// </summary> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询结果</returns> public static async Task <DataRow> ExecuteFirstRowAsync(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { //UNDONE using (var context = await query.ExecuteAsync(token)) { var data = context.LoadDataTable(0, 1); if (data.Rows.Count > 0) { return(data.Rows[0]); } else { return(null); } } }
/// <summary> /// 执行查询并返回首行 /// </summary> /// <param name="query">要执行的查询对象</param> /// <returns>查询结果</returns> public static DataRow ExecuteFirstRow(this IDbExecutable query) { //UNDONE using (var context = query.Execute()) { var data = context.LoadDataTable(0, 1); if (data.Rows.Count > 0) { return(data.Rows[0]); } else { return(null); } } }
/// <summary> /// 查询数据库并将结果首行填充实体 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换方法</param> /// <returns>实体</returns> public static T ExecuteEntity <T>(this IDbExecutable query, Func <DataRow, T> converter) { var dataItem = query.ExecuteFirstRow(); return(converter(dataItem)); }
/// <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> ExecuteEntityAsync <T>(this IDbExecutable query, IEntityConverter <T> converter, CancellationToken token = default(CancellationToken)) { var dataItem = await query.ExecuteFirstRowAsync(token); return(dataItem.ToEntity <T>(converter)); }
/// <summary> /// 查询数据库并将结果首行填充实体 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换方法</param> /// <returns>实体</returns> public static T ExecuteEntity <T>(this IDbExecutable query, IEntityConverter <T> converter) { var dataItem = query.ExecuteFirstRow(); return(dataItem.ToEntity <T>(converter)); }
/// <summary> /// 查询数据库并将结果首行填充实体 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <returns>实体</returns> public static T ExecuteEntity <T>(this IDbExecutable query) { var dataItem = query.ExecuteFirstRow(); return(dataItem.ToEntity <T>()); }
/// <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> /// 执行查询并将第一行数据数据转换为 DataRowView 返回 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>转换为 DataRowView 的数据集合</returns> public static DataRowView ExecuteFirstDataRowView(this IDbExecutable query) { return(query.ExecuteDataTable().GetRowViews().FirstOrDefault()); }
/// <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> /// 执行查询并将第一个结果集填充动态对象列表 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>查询结果</returns> public static dynamic[] ExecuteDynamics(this IDbExecutable query) { var data = query.ExecuteDataTable(); return(ToDynamics(data)); }
/// <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> /// 异步执行查询并返回首行首列 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="query">要执行的查询对象</param> /// <param name="token">取消指示</param> /// <returns>查询结果</returns> public async static Task <T> ExecuteScalarAsync <T>(this IDbExecutable query, CancellationToken token = default(CancellationToken)) { return(DbValueConverter.ConvertFrom <T>(await ExecuteScalarAsync(query, token))); }
/// <summary> /// 执行查询并将数据转换为 DataRowView 集合返回 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>转换为 DataRowView 的数据集合</returns> public static IEnumerable <DataRowView> ExecuteDataRowViews(this IDbExecutable query) { return(query.ExecuteDataTable().GetRowViews()); }
/// <summary> /// 查询数据库并将第一个结果集填充实体类型 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换器</param> /// <returns>实体集</returns> public static T[] ExecuteEntities <T>(this IDbExecutable query, Func <DataRow, T> converter) { var data = query.ExecuteDataTable(); return(data.GetRows().Select(dataItem => converter(dataItem)).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> ExecuteEntityAsync <T>(this IDbExecutable query, Func <DataRow, CancellationToken, Task <T> > converter, CancellationToken token = default(CancellationToken)) { var dataItem = await query.ExecuteFirstRowAsync(token); return(await converter(dataItem, token)); }
/// <summary> /// 执行查询并将第一个结果集的第一条记录填充动态对象 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>查询结果</returns> public static dynamic ExecuteDynamicObject(this IDbExecutable query) { var dataItem = query.ExecuteFirstRow(); return(ToDynamic(dataItem)); }
/// <summary> /// 异步执行查询并将第一个结果集的第一条记录填充动态对象 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>查询结果</returns> public static async Task <dynamic> ExecuteDynamicObjectAsync(this IDbExecutable query) { var dataItem = await query.ExecuteFirstRowAsync(); return(ToDynamic(dataItem)); }
/// <summary> /// 查询数据库并将第一个结果集填充实体类型 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换器</param> /// <returns>实体集</returns> public static T[] ExecuteEntities <T>(this IDbExecutable query, IEntityConverter <T> converter) { var data = query.ExecuteDataTable(); return(data.GetRows().Select(dataItem => dataItem.ToEntity(converter)).ToArray()); }
/// <summary> /// 执行查询并返回首行首列 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="query">要执行的查询对象</param> /// <returns>查询结果</returns> public static T ExecuteScalar <T>(this IDbExecutable query) { return(DbValueConverter.ConvertFrom <T>(ExecuteScalar(query))); }
/// <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> /// <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>()); }