Example #1
0
 public void NonQuery(string procedure, ParametersBuilder parametersBuilder = null)
 {
     this.RunCommand(
         procedure,
         command => command.ExecuteNonQuery(),
         parametersBuilder
         );
 }
Example #2
0
        public object Scalar(string procedure, ParametersBuilder parametersBuilder = null)
        {
            object output = null;

            this.RunCommand(
                procedure,
                command => output = command.ExecuteScalar(),
                parametersBuilder
                );

            return(output);
        }
Example #3
0
        protected void RunCommand(string procedure, Action <IDbCommand> closure, ParametersBuilder parametersBuilder = null)
        {
            parametersBuilder = parametersBuilder ?? ParametersBuilder.DefaultInstance;

            using (var command = this.connection.CreateCommand())
            {
                command.Transaction = this.transaction;
                command.CommandText = procedure;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection  = connection;

                parametersBuilder.SetupDbCommand(command);

                closure(command);
            }
        }
Example #4
0
        public T GetOne <T>(string procedure, Func <IDataReader, T> fetchClosure, ParametersBuilder parametersBuilder = null)
        {
            T output = default(T);

            void iterateAndFetch(IDbCommand command)
            {
                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        output = fetchClosure(reader);
                    }
                }
            }

            this.RunCommand(
                procedure,
                iterateAndFetch,
                parametersBuilder
                );

            return(output);
        }
Example #5
0
        public IEnumerable <T> Get <T>(string procedure, Func <IDataReader, T> fetchClosure, ParametersBuilder parametersBuilder = null)
        {
            var output = new List <T>();

            void iterateAndFetch(IDbCommand command)
            {
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var item = fetchClosure(reader);
                        output.Add(item);
                    }
                }
            }

            this.RunCommand(
                procedure,
                iterateAndFetch,
                parametersBuilder
                );

            return(output);
        }
Example #6
0
        public IEnumerable <T> GetDirect <T>(string procedure, Func <IDataReader, T> fetchClosure, ParametersBuilder parametersBuilder = null)
        {
            var output = this.Run <IEnumerable <T> >(() => this.Get(procedure, fetchClosure, parametersBuilder), false);

            return(output);
        }
Example #7
0
        public T GetOneDirect <T>(string procedure, Func <IDataReader, T> fetchClosure, ParametersBuilder parametersBuilder = null)
        {
            var output = this.Run(() => this.GetOne(procedure, fetchClosure, parametersBuilder), false);

            return(output);
        }
Example #8
0
        public object ScalarDirect(string procedure, ParametersBuilder parametersBuilder = null)
        {
            var output = this.Run <object>(() => this.Scalar(procedure, parametersBuilder), false);

            return(output);
        }
Example #9
0
 public void NonQueryDirect(string procedure, ParametersBuilder parametersBuilder = null)
 {
     this.Run(() => this.NonQuery(procedure, parametersBuilder), false);
 }
        /// <summary>
        /// Starts a new ParametersBuilder list with a first parameter.
        /// </summary>
        /// <typeparam name="T">The type of the parameter to be added. It will usually map automatically just fine based on your variable type.</typeparam>
        /// <param name="name">Name of the stored procedure parameter, without a prefix @.</param>
        /// <param name="value">Value of the stored procedure parameter.</param>
        /// <returns>Returns the new ParametersBuilder list with a first parameter added.</returns>
        public static ParametersBuilder With <T>(string name, T value)
        {
            var builder = new ParametersBuilder();

            return(builder.And <T>(name, value));
        }