コード例 #1
0
 /// <summary>
 /// Gets one result value
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cmd"></param>
 /// <param name="converter"></param>
 /// <returns></returns>
 public static T GetValue <T>(this DbCommand cmd, Func <object, T> converter = null)
 {
     try
     {
         object rez = cmd.ExecuteScalar();
         SqlFuManager.Config.OnCommand(cmd);
         return(SqlFuManager.GetConverter(converter)(rez));
     }
     catch (DbException ex)
     {
         SqlFuManager.Config.OnException(cmd, ex);
         throw;
     }
 }
コード例 #2
0
        public static async Task <T> GetValueAsync <T>(this DbCommand cmd, CancellationToken token, Func <object, T> converter = null)
        {
            try
            {
                object rez = await cmd.ExecuteScalarAsync(token).ConfigureAwait(false);

                SqlFuManager.Config.OnCommand(cmd);
                return(SqlFuManager.GetConverter(converter)(rez));
            }
            catch (DbException ex)
            {
                SqlFuManager.Config.OnException(cmd, ex);
                throw;
            }
        }
コード例 #3
0
 /// <summary>
 /// Gets one result value
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cmd"></param>
 /// <param name="converter"></param>
 /// <returns></returns>
 public static T GetValue <T>(this DbCommand cmd, Func <object, T> converter = null)
 {
     return(SqlFuManager.GetConverter(converter)(cmd.ExecuteScalar()));
 }
コード例 #4
0
 public static async Task <T> GetValueAsync <T>(this DbCommand cmd, CancellationToken token, Func <object, T> converter = null)
 {
     return(SqlFuManager.GetConverter(converter)(await cmd.ExecuteScalarAsync(token).ConfigureAwait(false)));
 }