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)
 {
 }
コード例 #3
0
 public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>(
     this Database database,
     string sqlString,
     IResultSetMapper <TResult> resultSetMapper)
 {
     return((DataAccessor <TResult>) new SqlStringAccessor <TResult>(database, sqlString, resultSetMapper));
 }
コード例 #4
0
        protected override void Arrange()
        {
            base.Arrange();

            parameterMapper = new ParameterMapper();
            resultSetMapper = new ResultSetMapper();
        }
コード例 #5
0
 public static IEnumerable <TResult> ExecuteSqlStringAccessor <TResult>(
     this Database database,
     string sqlString,
     IResultSetMapper <TResult> resultSetMapper)
 {
     return(database.CreateSqlStringAccessor <TResult>(sqlString, resultSetMapper).Execute());
 }
コード例 #6
0
 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));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
ファイル: DatabaseExt.cs プロジェクト: marcoholmes/KeepAlive
        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);
            }
        }
コード例 #9
0
 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;
 }
コード例 #11
0
        //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;
 }
コード例 #14
0
 /// <summary>
 /// Creates a <see cref="SqlStringAccessor&lt;TResult&gt;"/> for the given Transact-SQL query.
 /// </summary>
 /// <typeparam name="TResult">The type the <see cref="SprocAccessor&lt;TResult&gt;"/> 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&lt;TResult&gt;"/>.</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&lt;TResult&gt;"/> 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&lt;TResult&gt;"/>.</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));
 }
コード例 #16
0
        /// <summary>
        /// Creates a <see cref="SprocAccessor&lt;TResult&gt;"/> for the given stored procedure.
        /// </summary>
        /// <typeparam name="TResult">The type the <see cref="SprocAccessor&lt;TResult&gt;"/> should return when executing.</typeparam>
        /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> 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&lt;TResult&gt;"/>. </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&lt;TResult&gt;"/>.</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));
        }
コード例 #17
0
 /// <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&lt;TResult&gt;"/> 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));
 }
コード例 #18
0
 /// <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());
 }
コード例 #19
0
 /// <summary>
 /// Creates a new instance of <see cref="SprocAccessor&lt;TResult&gt;"/> 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&lt;TResult&gt;"/> 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)
 {
 }
コード例 #20
0
        /// <summary>
        /// Creates a new instance of <see cref="SprocAccessor&lt;TResult&gt;"/> 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&lt;TResult&gt;"/> 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;
        }