public void NonQuery(string procedure, ParametersBuilder parametersBuilder = null) { this.RunCommand( procedure, command => command.ExecuteNonQuery(), parametersBuilder ); }
public object Scalar(string procedure, ParametersBuilder parametersBuilder = null) { object output = null; this.RunCommand( procedure, command => output = command.ExecuteScalar(), parametersBuilder ); return(output); }
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); } }
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); }
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); }
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); }
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); }
public object ScalarDirect(string procedure, ParametersBuilder parametersBuilder = null) { var output = this.Run <object>(() => this.Scalar(procedure, parametersBuilder), false); return(output); }
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)); }