/// <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; } }
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; } }
/// <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())); }
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))); }