예제 #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> ExecuteEntityAsync <T>(this IDbExecutable query, IEntityConverter <T> converter, CancellationToken token = default(CancellationToken))
        {
            var dataItem = await query.ExecuteFirstRowAsync(token);

            return(dataItem.ToEntity <T>(converter));
        }
예제 #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> 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));
        }
예제 #3
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));
        }