Esempio n. 1
0
        /// <summary>
        /// Adds the given DbCommand and parameters to the current CommandBlock.
        /// </summary>
        /// <param name="dbCommand">Given DAAB DbCommand object.</param>
        public void AddDbCommand(DbCommand dbCommand)
        {
            if (dbCommand == null)
            {
                throw new ExceptionEvent(enumExceptionEventCodes.NullOrEmptyParameter
                                         , "dbCommand, cannot add a dbCommand that is null");
            }

            if (dbCommand.CommandType == System.Data.CommandType.StoredProcedure)
            {
                AddStoredProcedure(dbCommand.CommandText, _daMgr.CloneParameterCollection(dbCommand.Parameters));
            }

            else if (dbCommand.Parameters.Count > 0 ||
                     dbCommand.CommandText != _daMgr.BuildNoOpDbCommand().CommandText)       // dont add the empty command
            {
                AddDynamicSQL(dbCommand.CommandText, _daMgr.CloneParameterCollection(dbCommand.Parameters));
            }

            if (dbCommand.Site != null && dbCommand.Site is ParameterSite)
            {
                List <DbPredicateParameter> oldParams = new List <DbPredicateParameter>(
                    (List <DbPredicateParameter>)dbCommand.Site.GetService(null));

                List <DbPredicateParameter> copiedParams = new List <DbPredicateParameter>();

                foreach (DbPredicateParameter param in oldParams)
                {
                    DbPredicateParameter newParam = new DbPredicateParameter(param);

                    if (_paramAliases.ContainsKey(param.ParameterName))
                    {
                        string newName = _paramAliases[param.ParameterName].FirstOrDefault().ParameterName;

                        if (newName != null)
                        {
                            newParam.ParameterName = newName;
                        }
                    }

                    copiedParams.Add(newParam);
                }

                if (_dbCommand.Site == null)
                {
                    _dbCommand.Site = new ParameterSite(copiedParams);
                }
                else if (_dbCommand.Site is ParameterSite)
                {
                    ((List <DbPredicateParameter>)_dbCommand.Site.GetService(null)).AddRange(copiedParams);
                }
            }
        }