예제 #1
0
 /// <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);
     }
 }
예제 #2
0
 /// <summary>
 /// 执行没有结果的查询
 /// </summary>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询所影响的行数</returns>
 public static int ExecuteNonQuery(this IDbExecutable query)
 {
     using (var context = query.Execute())
     {
         return(context.RecordsAffected);
     }
 }
예제 #3
0
 /// <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));
     }
 }
예제 #4
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));
     }
 }
예제 #5
0
        /// <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());
        }
예제 #6
0
        /// <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());
        }
예제 #7
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());
        }
예제 #8
0
        /// <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);
                }
            }
        }
예제 #9
0
        /// <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);
                }
            }
        }
예제 #10
0
        /// <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);
                }
            }
        }
예제 #11
0
        /// <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);
                }
            }
        }
예제 #12
0
        /// <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));
        }
예제 #13
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> ExecuteEntityAsync <T>(this IDbExecutable query, IEntityConverter <T> converter, CancellationToken token = default(CancellationToken))
        {
            var dataItem = await query.ExecuteFirstRowAsync(token);

            return(dataItem.ToEntity <T>(converter));
        }
예제 #14
0
        /// <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));
        }
예제 #15
0
        /// <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>());
        }
예제 #16
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());
 }
예제 #17
0
 /// <summary>
 /// 执行查询并将第一行数据数据转换为 DataRowView 返回
 /// </summary>
 /// <param name="query">要执行的查询</param>
 /// <returns>转换为 DataRowView 的数据集合</returns>
 public static DataRowView ExecuteFirstDataRowView(this IDbExecutable query)
 {
     return(query.ExecuteDataTable().GetRowViews().FirstOrDefault());
 }
예제 #18
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());
 }
예제 #19
0
        /// <summary>
        /// 执行查询并将第一个结果集填充动态对象列表
        /// </summary>
        /// <param name="query">要执行的查询</param>
        /// <returns>查询结果</returns>
        public static dynamic[] ExecuteDynamics(this IDbExecutable query)
        {
            var data = query.ExecuteDataTable();

            return(ToDynamics(data));
        }
예제 #20
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));
        }
예제 #21
0
 /// <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)));
 }
예제 #22
0
 /// <summary>
 /// 执行查询并将数据转换为 DataRowView 集合返回
 /// </summary>
 /// <param name="query">要执行的查询</param>
 /// <returns>转换为 DataRowView 的数据集合</returns>
 public static IEnumerable <DataRowView> ExecuteDataRowViews(this IDbExecutable query)
 {
     return(query.ExecuteDataTable().GetRowViews());
 }
예제 #23
0
        /// <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());
        }
예제 #24
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> 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));
        }
예제 #25
0
        /// <summary>
        /// 执行查询并将第一个结果集的第一条记录填充动态对象
        /// </summary>
        /// <param name="query">要执行的查询</param>
        /// <returns>查询结果</returns>
        public static dynamic ExecuteDynamicObject(this IDbExecutable query)
        {
            var dataItem = query.ExecuteFirstRow();

            return(ToDynamic(dataItem));
        }
예제 #26
0
        /// <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));
        }
예제 #27
0
        /// <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());
        }
예제 #28
0
 /// <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)));
 }
예제 #29
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());
        }
예제 #30
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>());
 }