/// <summary>
        ///  <para>Creates an <see cref="IDbJob{List{object}}"/> able to execute a reader based on the configured parameters.</para>
        /// <para>Valid types: <see cref="DataSet"/>, <see cref="DataTable"/>, <see cref="Dictionary{string,object}"/>, any .NET built-in type, or any struct or class with a parameterless constructor not assignable from <see cref="System.Collections.IEnumerable"/> (Note: only properties will be mapped).</para>
        ///  See also:
        ///  <seealso cref="DbCommand.ExecuteReader()"/>
        /// </summary>
        /// <remarks>
        /// This will use the <see cref="CommandBehavior.SingleResult"/> behavior by default.
        /// </remarks>
        /// <param name="type">The <see cref="Type"/> to use.</param>
        /// <param name="mapSettings">The <see cref="IColumnMapSetting"/> to use.</param>
        /// <param name="sql">The query text command to run against the data source.</param>
        /// <param name="param">The parameter to use. <see cref="DbJobParameterCollection.AddFor(object, bool, string, string)"/> restrictions apply. (Optional)</param>
        /// <param name="commandType">The <see cref="CommandType"/> to use. (Optional)</param>
        /// <param name="commandBehavior">The <see cref="CommandBehavior"/> to use. (Optional)</param>
        /// <param name="commandTimeout">The time in seconds to wait for the command to execute. (Optional)</param>
        /// <param name="flags">The flags to use. (Optional)</param>
        /// <returns>The <see cref="IDbJob{List{object}}"/>.</returns>
        public IDbJob <List <object> > ReadToList(
            Type type,
            IColumnMapSetting mapSettings,
            string sql,
            object param                    = null,
            CommandType commandType         = CommandType.Text,
            CommandBehavior?commandBehavior = null,
            int?commandTimeout              = null,
            DbJobCommandFlags flags         = DbJobCommandFlags.None)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type cannot be null!");
            }

            return(new DbJob <List <object>, TDbConnection>
                   (
                       setting: _jobSetting,
                       state: new DbConnectorSimpleState {
                Flags = _flags
            },
                       onCommands: (conn, state) => BuildJobCommandForSimpleState(conn, state, mapSettings, sql, param, commandType, commandBehavior, commandTimeout, flags),
                       onExecute: (d, p) => OnExecuteReadToList(type, p)
                   ).SetOnError((d, e) => new List <object>()));
        }
        /// <summary>
        ///  <para>Creates an <see cref="IDbJob{object}"/> able to execute a reader based on the configured parameters.</para>
        ///  <para>Use this to load only a single row from the query result into an object.</para>
        /// <para>Valid types: <see cref="DataSet"/>, <see cref="DataTable"/>, <see cref="Dictionary{string,object}"/>, any .NET built-in type, or any struct or class with a parameterless constructor not assignable from <see cref="System.Collections.IEnumerable"/> (Note: only properties will be mapped).</para>
        ///  See also:
        ///  <seealso cref="DbCommand.ExecuteReader()"/>
        /// </summary>
        /// <remarks>
        /// This will use the <see cref="CommandBehavior.SingleResult"/> behavior by default.
        /// </remarks>
        /// <param name="type">The <see cref="Type"/> to use.</param>
        /// <param name="mapSettings">The <see cref="IColumnMapSetting"/> to use.</param>
        /// <param name="sql">The query text command to run against the data source.</param>
        /// <param name="param">The parameter to use. <see cref="DbJobParameterCollection.AddFor(object, bool, string, string)"/> restrictions apply. (Optional)</param>
        /// <param name="commandType">The <see cref="CommandType"/> to use. (Optional)</param>
        /// <param name="commandBehavior">The <see cref="CommandBehavior"/> to use. (Optional)</param>
        /// <param name="commandTimeout">The time in seconds to wait for the command to execute. (Optional)</param>
        /// <param name="flags">The flags to use. (Optional)</param>
        /// <returns>The <see cref="IDbJob{object}"/>.</returns>
        /// <exception cref="InvalidOperationException">The query result has more than one result.</exception>
        public IDbJob <object> ReadSingleOrDefault(
            Type type,
            IColumnMapSetting mapSettings,
            string sql,
            object param                    = null,
            CommandType commandType         = CommandType.Text,
            CommandBehavior?commandBehavior = null,
            int?commandTimeout              = null,
            DbJobCommandFlags flags         = DbJobCommandFlags.None)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type cannot be null!");
            }

            return(new DbJob <object, TDbConnection>
                   (
                       setting: _jobSetting,
                       state: new DbConnectorSimpleState {
                Flags = _flags
            },
                       onInit: () => type.IsValueType ? Activator.CreateInstance(type) : null,
                       onCommands: (conn, state) => BuildJobCommandForSimpleState(conn, state, mapSettings, sql, param, commandType, commandBehavior, commandTimeout, flags),
                       onExecute: (d, p) => OnExecuteReadSingleOrDefault(type, p)
                   ));
        }
Esempio n. 3
0
 /// <summary>
 ///  <para>Creates an <see cref="IDbJob{IEnumerable{dynamic}}"/> able to execute a reader based on the configured parameters.</para>
 ///  <para>Use this to dynamically load the query results into an IEnumerable of <see cref="System.Dynamic.ExpandoObject"/>.</para>
 ///  See also:
 ///  <seealso cref="DbCommand.ExecuteReader()"/>
 /// </summary>
 /// <remarks>
 /// This will use the <see cref="CommandBehavior.SingleResult"/> behavior by default.
 /// </remarks>
 /// <param name="mapSettings">The <see cref="IColumnMapSetting"/> to use.</param>
 /// <param name="sql">The query text command to run against the data source.</param>
 /// <param name="param">The parameter to use. <see cref="DbJobParameterCollection.AddFor(object, bool, string, string)"/> restrictions apply. (Optional)</param>
 /// <param name="commandType">The <see cref="CommandType"/> to use. (Optional)</param>
 /// <param name="commandBehavior">The <see cref="CommandBehavior"/> to use. (Optional)</param>
 /// <param name="commandTimeout">The time in seconds to wait for the command to execute. (Optional)</param>
 /// <param name="flags">The flags to use. (Optional)</param>
 /// <returns>The <see cref="IDbJob{IEnumerable{dynamic}}"/>.</returns>
 public IDbJob <IEnumerable <dynamic> > Read(
     IColumnMapSetting mapSettings,
     string sql,
     object param                    = null,
     CommandType commandType         = CommandType.Text,
     CommandBehavior?commandBehavior = null,
     int?commandTimeout              = null,
     DbJobCommandFlags flags         = DbJobCommandFlags.None)
 {
     return(new DbJob <IEnumerable <dynamic>, TDbConnection>
            (
                setting: _jobSetting,
                state: new DbConnectorSimpleState {
         Flags = _flags
     },
                onCommands: (conn, state) => BuildJobCommandForSimpleState(conn, state, mapSettings, sql, param, commandType, commandBehavior, commandTimeout, flags),
                onExecute: (d, p) => OnExecuteReadDynamic(d, p)
            ).SetOnError((d, e) => Enumerable.Empty <dynamic>()));
 }
Esempio n. 4
0
 /// <summary>
 ///  <para>Creates an <see cref="IDbJob{dynamic}"/> able to execute a reader based on the configured parameters.</para>
 ///  <para>Use this to dynamically load only a single row from the query result into a <see cref="System.Dynamic.ExpandoObject"/>.</para>
 ///  See also:
 ///  <seealso cref="DbCommand.ExecuteReader()"/>
 /// </summary>
 /// <remarks>
 /// This will use the <see cref="CommandBehavior.SingleResult"/> behavior by default.
 /// </remarks>
 /// <param name="mapSettings">The <see cref="IColumnMapSetting"/> to use.</param>
 /// <param name="sql">The query text command to run against the data source.</param>
 /// <param name="param">The parameter to use. <see cref="DbJobParameterCollection.AddFor(object, bool, string, string)"/> restrictions apply. (Optional)</param>
 /// <param name="commandType">The <see cref="CommandType"/> to use. (Optional)</param>
 /// <param name="commandBehavior">The <see cref="CommandBehavior"/> to use. (Optional)</param>
 /// <param name="commandTimeout">The time in seconds to wait for the command to execute. (Optional)</param>
 /// <param name="flags">The flags to use. (Optional)</param>
 /// <returns>The <see cref="IDbJob{dynamic}"/>.</returns>
 /// <exception cref="InvalidOperationException">The query result has more than one result.</exception>
 public IDbJob <dynamic> ReadSingleOrDefault(
     IColumnMapSetting mapSettings,
     string sql,
     object param                    = null,
     CommandType commandType         = CommandType.Text,
     CommandBehavior?commandBehavior = null,
     int?commandTimeout              = null,
     DbJobCommandFlags flags         = DbJobCommandFlags.None)
 {
     return(new DbJob <dynamic, TDbConnection>
            (
                setting: _jobSetting,
                state: new DbConnectorSimpleState {
         Flags = _flags
     },
                onCommands: (conn, state) => BuildJobCommandForSimpleState(conn, state, mapSettings, sql, param, commandType, commandBehavior, commandTimeout, flags),
                onExecute: (d, p) => OnExecuteReadSingleOrDefaultDynamic(d, p)
            ));
 }
        /// <summary>
        ///  <para>Creates an <see cref="IDbJob{object}"/> to get the first column of the first row in the result
        ///  set returned by the query. All other columns and rows are ignored.</para>
        ///  See also:
        ///  <seealso cref="DbCommand.ExecuteScalar"/>
        /// </summary>
        /// <param name="mapSettings">The <see cref="IColumnMapSetting"/> to use.</param>
        /// <param name="sql">The query text command to run against the data source.</param>
        /// <param name="param">The parameter to use. <see cref="DbJobParameterCollection.AddFor(object, bool, string, string)"/> restrictions apply. (Optional)</param>
        /// <param name="commandType">The <see cref="CommandType"/> to use. (Optional)</param>
        /// <param name="commandBehavior">The <see cref="CommandBehavior"/> to use. (Optional)</param>
        /// <param name="commandTimeout">The time in seconds to wait for the command to execute. (Optional)</param>
        /// <param name="flags">The flags to use. (Optional)</param>
        /// <returns>The <see cref="IDbJob{object}"/>.</returns>
        public IDbJob <object> Scalar(
            IColumnMapSetting mapSettings,
            string sql,
            object param                    = null,
            CommandType commandType         = CommandType.Text,
            CommandBehavior?commandBehavior = null,
            int?commandTimeout              = null,
            DbJobCommandFlags flags         = DbJobCommandFlags.None)
        {
            return(new DbJob <object, TDbConnection>
                   (
                       setting: _jobSetting,
                       state: new DbConnectorSimpleState {
                Flags = _flags
            },
                       onCommands: (conn, state) => BuildJobCommandForSimpleState(conn, state, mapSettings, sql, param, commandType, commandBehavior, commandTimeout, flags),
                       onExecute: (d, p) =>
            {
                object scalar = p.Command.ExecuteScalar();

                return scalar != DBNull.Value ? scalar : null;
            }
                   ));
        }