Exemple #1
0
        public static int ExecuteNonQuery(
            this IDbCmd source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            using (var cmd = source.CreateAndOpen())
            {
                return(cmd.ExecuteNonQuery());
            }
        }
Exemple #2
0
        /// <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));
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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));
            }
        }
Exemple #5
0
        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);
            }
        }