public SqlStringAccessor( Database database, string sqlString, IResultSetMapper <TResult> resultSetMapper) : this(database, sqlString, (IParameterMapper) new SqlStringAccessor <TResult> .DefaultSqlStringParameterMapper(), resultSetMapper) { }
public SprocAccessor( Database database, string procedureName, IResultSetMapper <TResult> resultSetMapper) : this(database, procedureName, (IParameterMapper) new SprocAccessor <TResult> .DefaultParameterMapper(database), resultSetMapper) { }
public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>( this Database database, string sqlString, IResultSetMapper <TResult> resultSetMapper) { return((DataAccessor <TResult>) new SqlStringAccessor <TResult>(database, sqlString, resultSetMapper)); }
protected override void Arrange() { base.Arrange(); parameterMapper = new ParameterMapper(); resultSetMapper = new ResultSetMapper(); }
public static IEnumerable <TResult> ExecuteSqlStringAccessor <TResult>( this Database database, string sqlString, IResultSetMapper <TResult> resultSetMapper) { return(database.CreateSqlStringAccessor <TResult>(sqlString, resultSetMapper).Execute()); }
public static IEnumerable <TResult> ExecuteSprocAccessor <TResult>( this Database database, string procedureName, IResultSetMapper <TResult> resultSetMapper, params object[] parameterValues) where TResult : new() { return(database.CreateSprocAccessor <TResult>(procedureName, resultSetMapper).Execute(parameterValues)); }
public static DataAccessor <TResult> CreateSprocAccessor <TResult>( this Database database, string procedureName, IResultSetMapper <TResult> resultSetMapper) { if (string.IsNullOrEmpty(procedureName)) { throw new ArgumentException(Resources.ExceptionNullOrEmptyString); } return((DataAccessor <TResult>) new SprocAccessor <TResult>(database, procedureName, resultSetMapper)); }
public static IEnumerable <TResult> ExecuteDbCommand <TResult>(this Database database, DbCommand command, IResultSetMapper <TResult> mapper) { IEnumerable <TResult> list = null; using (IDataReader reader = database.ExecuteReader(command)) { list = mapper.MapSet(reader); return(list); } }
public virtual IEnumerable <TEntity> GetAll(CustomCommand command, IRowMapper <TEntity> rowMapper) { SetConnectionString(); this.resultSetMapper = new DefaultResultSetMapper(rowMapper); using (var reader = Session.ExecuteReader(new CommandDefinition(command.SqlCommand, command.Parameters, commandType: command.CommandType))) { foreach (TEntity result in this.resultSetMapper.MapSet(reader)) { yield return(result); } } }
protected CommandAccessor(Database database, IResultSetMapper <TResult> resultSetMapper) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (resultSetMapper == null) { throw new ArgumentNullException(nameof(resultSetMapper)); } this.database = database; this.resultSetMapper = resultSetMapper; }
//public static IEnumerable<TResult> ExecuteSprocAccessor<TResult, TParam>(this Database database, // string storedProcedureName, // IParameterMapper parameterMapper, // IRowMapper<TResult> rowMapper, // params TParam[] parameterValues) // where TResult : new() // where TParam : KeyValueItem //{ // return database.CreateSprocAccessor(storedProcedureName, parameterMapper, rowMapper).Execute(parameterValues); //} public static IEnumerable <TResult> ExecuteSprocAccessor <TResult, TParam>(this Database database, string storedProcedureName, IResultSetMapper <TResult> resultSetMapper, params TParam[] parameterValues) where TResult : new() where TParam : KeyValueItem { var reader = database.ExecuteReader <TParam>(storedProcedureName, parameterValues); return(resultSetMapper.MapSet(reader)); //return ExecuteSprocAccessor<TResult, TParam>(database, storedProcedureName, // new KeyValueItemParameterMapper(database), resultSetMapper); }
public SprocAccessor( Database database, string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper) : base(database, resultSetMapper) { if (string.IsNullOrEmpty(procedureName)) { throw new ArgumentException(Resources.ExceptionNullOrEmptyString); } if (parameterMapper == null) { throw new ArgumentNullException(nameof(parameterMapper)); } this.procedureName = procedureName; this.parameterMapper = parameterMapper; }
public SqlStringAccessor( Database database, string sqlString, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper) : base(database, resultSetMapper) { if (string.IsNullOrEmpty(sqlString)) { throw new ArgumentException(Resources.ExceptionNullOrEmptyString); } if (parameterMapper == null) { throw new ArgumentNullException(nameof(parameterMapper)); } this.parameterMapper = parameterMapper; this.sqlString = sqlString; }
/// <summary> /// Creates a <see cref="SqlStringAccessor<TResult>"/> for the given Transact-SQL query. /// </summary> /// <typeparam name="TResult">The type the <see cref="SprocAccessor<TResult>"/> should return when executing.</typeparam> /// <param name="database">The <see cref="Database"/> that contains the stored procedure.</param> /// <param name="sqlString">The Transact-SQL query that will be executed by the <see cref="SqlStringAccessor<TResult>"/>.</param> /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param> /// <returns>A new instance of <see cref="SprocAccessor<TResult>"/>.</returns> public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>(this Database database, string sqlString, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper) { return(new SqlStringAccessor <TResult>(database, sqlString, parameterMapper, resultSetMapper)); }
public IEnumerable <T> ExecStoredProc <T>(string storeName, object[] paramObj, IResultSetMapper <T> resultMapper) where T : new() { return(_db.ExecuteSprocAccessor(storeName, resultMapper, paramObj)); }
/// <summary> /// Creates a <see cref="SprocAccessor<TResult>"/> for the given stored procedure. /// </summary> /// <typeparam name="TResult">The type the <see cref="SprocAccessor<TResult>"/> should return when executing.</typeparam> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param> /// <param name="procedureName">The name of the stored procedure that should be executed by the <see cref="SprocAccessor<TResult>"/>. </param> /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param> /// <returns>A new instance of <see cref="SprocAccessor<TResult>"/>.</returns> public DataAccessor <TResult> CreateDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper) { if (string.IsNullOrEmpty(procedureName)) { throw new ArgumentException(); } return(new Db2SprocAccessor <TResult>(this, procedureName, parameterMapper, resultSetMapper)); }
/// <summary> /// Executes a stored procedure and returns the result as an enumerable of <typeparamref name="TResult"/>. /// </summary> /// <typeparam name="TResult">The element type that will be returned when executing.</typeparam> /// <param name="procedureName">The name of the stored procedure that will be executed.</param> /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param> /// <param name="parameterValues">Parameter values passsed to the stored procedure.</param> /// <returns>An enumerable of <typeparamref name="TResult"/>.</returns> public IEnumerable <TResult> ExecuteDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper, params object[] parameterValues) where TResult : new() { return(CreateDb2SprocAccessor(procedureName, parameterMapper, resultSetMapper).Execute(parameterValues)); }
/// <summary> /// Executes a stored procedure and returns the result as an object of <typeparamref name="TResult"/>. /// /// </summary> /// <typeparam name="TResult">The element type that will be returned when executing.</typeparam> /// <param name="database">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Data.Database"/> /// that contains the stored procedure.</param><param name="procedureName">The name of the stored procedure that will be executed.</param> /// <param name="parameterValues">The parameter values thst should be passed to the stored procedure.</param> /// <param name="resultSetMappers">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Data.IResultSetMapper`1"/> /// that will be used to convert the returned data to clr type <typeparamref name="TResult"/>.</param> /// <returns> /// A paged collection of <typeparamref name="TResult"/>. /// </returns> public static TResult ExecuteSprocAccessorObject <TResult>(this Database database, string procedureName, IResultSetMapper <TResult> resultSetMappers, params object[] parameterValues) where TResult : new() { return(database.ExecuteSprocAccessor(procedureName, resultSetMappers, parameterValues).FirstOrDefault()); }
/// <summary> /// Creates a new instance of <see cref="SprocAccessor<TResult>"/> that works for a specific <paramref name="database"/> /// and uses <paramref name="resultSetMapper"/> to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>. /// </summary> /// <param name="database">The <see cref="Database"/> used to execute the Transact-SQL.</param> /// <param name="procedureName">The stored procedure that will be executed.</param> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param> public Db2SprocAccessor(Db2Database database, string procedureName, IResultSetMapper <TResult> resultSetMapper) : this(database, procedureName, new DefaultParameterMapper(database), resultSetMapper) { }
/// <summary> /// Creates a new instance of <see cref="SprocAccessor<TResult>"/> that works for a specific <paramref name="database"/> /// and uses <paramref name="resultSetMapper"/> to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>. /// The <paramref name="parameterMapper"/> will be used to interpret the parameters passed to the Execute method. /// </summary> /// <param name="database">The <see cref="Database"/> used to execute the Transact-SQL.</param> /// <param name="procedureName">The stored procedure that will be executed.</param> /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param> public Db2SprocAccessor(Db2Database database, string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper) : base(database, resultSetMapper) { if (string.IsNullOrEmpty(procedureName)) { throw new ArgumentException("The value can not be a null or empty string."); } if (parameterMapper == null) { throw new ArgumentNullException(nameof(parameterMapper)); } _procedureName = procedureName; _parameterMapper = parameterMapper; }