public static int ExecuteNonQuery( this IDbCmd source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } using (var cmd = source.CreateAndOpen()) { return(cmd.ExecuteNonQuery()); } }
/// <summary> /// Either read all items or use a using block to ensure all /// resources are fully cleaned up. /// </summary> /// <param name="source"></param> /// <returns></returns> public static IManagedEnumerable <T> AsEnumerable <T>( this IDbCmd source) where T : new() { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.CommandBehavior(CmdBehavior.SingleResult); var cmd = source.CreateAndOpen(); var reader = cmd.ExecuteReader(source); return(new ManagedEnumerable <T>(source, cmd, reader)); }
public static object ExecuteScalar( this IDbCmd source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } using (var cmd = source.CreateAndOpen()) { var obj = cmd.ExecuteScalar(); return(DBNull.Value.Equals(obj) ? null : obj); } }
public static T Execute <T>( this IDbCmd source, Func <IDbCommand, T> func) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (func == null) { throw new ArgumentNullException(nameof(func)); } using (var dbCmd = source.CreateAndOpen()) { return(func(dbCmd)); } }
public static void Execute( this IDbCmd source, Action <IDbCommand> action) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } using (var dbCmd = source.CreateAndOpen()) { action(dbCmd); } }