Пример #1
0
        /// <summary>
        ///     Add a new Command to the command list the command will be prepared after action.
        /// </summary>
        /// <param name="index">   index. </param>
        /// <param name="query">   query. </param>
        /// <param name="action">  (Optional) action. </param>
        /// <param name="prepare"> (Optional) true if prepare command; false otherwise. </param>
        /// <exception cref="NullReferenceException"> Thrown when a value was unexpectedly null. </exception>
        protected void Add(int index, string query, PrepareDbCommand <TCommand> action = null, bool prepare = true)
        {
            if (_connection == null)
            {
                throw new NullReferenceException("the connection is null pls initialize the connection first!");
            }

            TCommand cmd = new TCommand {
                CommandText = query, Connection = _connection
            };

            action?.Invoke(cmd);

            if (prepare)
            {
                cmd.Prepare();
            }

            _commands.Add(index, cmd);
        }
Пример #2
0
 /// <summary>
 ///     Add a new database command to the command list the command will be prepared after action.
 /// </summary>
 /// <typeparam name="TPrim"> struct, IConvertible. </typeparam>
 /// <param name="index">   index. </param>
 /// <param name="query">   query. </param>
 /// <param name="action">  (Optional) action. </param>
 /// <param name="prepare"> (Optional) true if prepare command; false otherwise. </param>
 protected void Add <TPrim>(TPrim index, string query, PrepareDbCommand <TCommand> action = null,
                            bool prepare = true)
     where TPrim : struct, IConvertible
 {
     Add((int)Convert.ChangeType(index, typeof(int)), query, action, prepare);
 }