protected void SetParameter(string paramName,
                                    object paramValue,
                                    SqlDbType sqlDbType,
                                    bool isNullable,
                                    ParameterDirection direction,
                                    int size = 0)
        {
            if (string.IsNullOrEmpty(paramName))
            {
                throw new ArgumentNullException("paramName", "Name of parameter is not defined!");
            }

            QueryParameterConfig config = new QueryParameterConfig
            {
                ParameterName = paramName,
                IsStoredProcedureParameter = true, // TRUE since it's always an SP parameter
                IsNullable = isNullable,
                Size       = size,
                Direction  = direction,
                DbType     = sqlDbType
            };

            // set parameter in the parent class
            SetParameter(paramName, paramValue, config);
        }
Exemple #2
0
 protected bool Equals(QueryParameterConfig other)
 {
     return(DbType == other.DbType &&
            Size == other.Size &&
            IsStoredProcedureParameter == other.IsStoredProcedureParameter &&
            NoQuotes == other.NoQuotes &&
            IsNullable == other.IsNullable &&
            Direction == other.Direction);
 }
Exemple #3
0
        protected virtual void SetParameter(string paramName, object paramValue, QueryParameterConfig config)
        {
            if (string.IsNullOrEmpty(paramName))
            {
                throw new ArgumentNullException("paramName");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config", "Parameter configuration is not defined!");
            }



            // get a parameter from the parameters hashmap
            QueryParameterEntry entry = (QueryParameterEntry)ParametersMap[paramName];

            if ((entry != null) && (entry.Config != null) && entry.Config.Equals(config))
            {
                // entry is found for parameter
                // just create a new DB parameter
                // leave the parameter config untouched if it did not change
                if (ExecutedTimes > 0)
                {
                    SqlParameter newDbParameter = config.IsStoredProcedureParameter
                        ? DbContext.CreateStoredProcParameter(
                        paramName: paramName, paramValue: paramValue,
                        direction: config.Direction, sqlDbType: config.DbType,
                        isNullable: config.IsNullable, size: config.Size)
                        : DbContext.CreateParameter(paramName, paramValue);

                    // reset parameter with a one with updated values
                    entry.Parameter = newDbParameter;
                    return;
                }

                // just reset the parameter value
                // without re-creating parameter
                entry.Parameter.Value = paramValue ?? DBNull.Value;
            }
            else
            {
                SqlParameter newDbParameter = config.IsStoredProcedureParameter
                    ? DbContext.CreateStoredProcParameter(
                    paramName: paramName,
                    paramValue: paramValue,
                    direction: config.Direction,
                    sqlDbType: config.DbType,
                    isNullable: config.IsNullable,
                    size: config.Size)
                    : DbContext.CreateParameter(paramName, paramValue);

                // create a new parameter entry, contating the parameter itself and its configuration
                QueryParameterEntry newEntry = new QueryParameterEntry
                {
                    Parameter = newDbParameter,
                    Config    = config
                };

                // save entry in the parameters map
                ParametersMap[paramName] = newEntry;
            }
        }