Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="System.Data.IDbCommand"/> to
        /// use with the current data provider and initializes
        /// its text, timeouts and parameters.
        /// </summary>
        protected virtual IDbCommand CreateCommand()
        {
            IDbCommand command = _provider.CreateCommand();

            if (_command == null)
            {
                return(command);
            }

            command.CommandText    = _command.Text;
            command.CommandTimeout = _command.Timeout;
            command.CommandType    = _command.Type;

            foreach (DbParameterDescriptor pd in _command.Parameters)
            {
                IDbDataParameter parameter = command.CreateParameter();
                parameter.ParameterName = pd.Name;
                parameter.Direction     = pd.Direction;
                parameter.Precision     = pd.Precision;
                parameter.Scale         = pd.Scale;
                parameter.Value         = pd.Value;

                if (pd.Size.HasValue)
                {
                    parameter.Size = pd.Size.GetValueOrDefault();
                }

                command.Parameters.Add(parameter);
            }
            return(command);
        }