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

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

            return(output);
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #8
0
        public object ScalarDirect(string procedure, ParametersBuilder parametersBuilder = null)
        {
            var output = this.Run <object>(() => this.Scalar(procedure, parametersBuilder), false);

            return(output);
        }
コード例 #9
0
 public void NonQueryDirect(string procedure, ParametersBuilder parametersBuilder = null)
 {
     this.Run(() => this.NonQuery(procedure, parametersBuilder), false);
 }
コード例 #10
0
        /// <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));
        }