コード例 #1
0
        private static T FieldValue <T>(this DataRow dataRow, DataColumn column)
        {
            if (dataRow == null)
            {
                throw new ArgumentNullException("dataRow");
            }

            if (column == null)
            {
                throw new ArgumentNullException("column");
            }


            try
            {
                return(DbValueConverter.ConvertFrom <T>(dataRow[column]));
            }
            catch (Exception e)
            {
                e.Data.Add("DataColumnName", column.ColumnName);
                throw;
            }
        }
コード例 #2
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 IAsyncDbExecutableQuery query, CancellationToken token = default(CancellationToken))
 {
     return(DbValueConverter.ConvertFrom <T>(await ExecuteScalarAsync(query, token)));
 }
コード例 #3
0
 /// <summary>
 /// 执行查询并返回首行首列
 /// </summary>
 /// <typeparam name="T">返回值类型</typeparam>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询结果</returns>
 public static T ExecuteScalar <T>(this IDbExecutableQuery query)
 {
     return(DbValueConverter.ConvertFrom <T>(ExecuteScalar(query)));
 }