ReturnValue Duplicate Parameter in ActionProcedure

Posts   
 
    
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 09-May-2006 18:50:55   

Adapter 2.0 Beta May 5th, 2006

I'm doing what most of us hate and using someone else's database. There are stored procedures in that database that have parameters named 'returnValue', so when your code adds in a parameter called 'returnValue', the compiler generates a 'The parameter name 'returnValue' is a duplicate' error

Generated code:

/// <summary>
        /// Calls stored procedure 'CopyDepartments'.<br/><br/>
        /// 
        /// </summary>
        /// <param name="companyId">Input parameter of stored procedure</param>
        /// <param name="departmentId">Input parameter of stored procedure</param>
        /// <param name="departmentName">Input parameter of stored procedure</param>
        /// <param name="targetId">Input parameter of stored procedure</param>
        /// <param name="userId">Input parameter of stored procedure</param>
        /// <param name="newDepartmentId">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">InputOutput parameter of stored procedure</param>
        /// <returns>Amount of rows affected, if the database / routine doesn't surpress rowcounting.</returns>
        public static int CopyDepartments(System.Int32 companyId, System.Int32 departmentId, System.String departmentName, System.Int32 targetId, System.Int32 userId, ref System.Int32 newDepartmentId, ref System.Int32 returnValue)
        {
            using(DataAccessAdapter adapter = new DataAccessAdapter())
            {
                return CopyDepartments(companyId, departmentId, departmentName, targetId, userId, ref newDepartmentId, ref returnValue,  adapter);
            }
        }


        /// <summary>
        /// Calls stored procedure 'CopyDepartments'.<br/><br/>
        /// 
        /// </summary>
        /// <param name="companyId">Input parameter of stored procedure</param>
        /// <param name="departmentId">Input parameter of stored procedure</param>
        /// <param name="departmentName">Input parameter of stored procedure</param>
        /// <param name="targetId">Input parameter of stored procedure</param>
        /// <param name="userId">Input parameter of stored procedure</param>
        /// <param name="newDepartmentId">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">InputOutput parameter of stored procedure</param>
        /// <param name="adapter">The DataAccessAdapter object to use for the call</param>
        /// <returns>Amount of rows affected, if the database / routine doesn't surpress rowcounting.</returns>
        public static int CopyDepartments(System.Int32 companyId, System.Int32 departmentId, System.String departmentName, System.Int32 targetId, System.Int32 userId, ref System.Int32 newDepartmentId, ref System.Int32 returnValue, DataAccessAdapter adapter)
        {
            SqlParameter[] parameters = new SqlParameter[7];
            parameters[0] = new SqlParameter("@CompanyID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, companyId);
            parameters[1] = new SqlParameter("@DepartmentID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, departmentId);
            parameters[2] = new SqlParameter("@DepartmentName", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "",  DataRowVersion.Current, departmentName);
            parameters[3] = new SqlParameter("@TargetID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, targetId);
            parameters[4] = new SqlParameter("@UserID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, userId);
            parameters[5] = new SqlParameter("@NewDepartmentID", SqlDbType.Int, 0, ParameterDirection.InputOutput, true, 10, 0, "",  DataRowVersion.Current, newDepartmentId);
            parameters[6] = new SqlParameter("@ReturnValue", SqlDbType.Int, 0, ParameterDirection.InputOutput, true, 10, 0, "",  DataRowVersion.Current, returnValue);
            int toReturn = adapter.CallActionStoredProcedure("[qqest].[dbo].[CopyDepartments]", parameters);
            if(parameters[5].Value!=System.DBNull.Value)
            {
                newDepartmentId = (System.Int32)parameters[5].Value;
            }
            if(parameters[6].Value!=System.DBNull.Value)
            {
                returnValue = (System.Int32)parameters[6].Value;
            }
            return toReturn;
        }
        

        /// <summary>
        /// Calls stored procedure 'CopyDepartments'.<br/><br/>
        /// 
        /// </summary>
        /// <param name="companyId">Input parameter of stored procedure</param>
        /// <param name="departmentId">Input parameter of stored procedure</param>
        /// <param name="departmentName">Input parameter of stored procedure</param>
        /// <param name="targetId">Input parameter of stored procedure</param>
        /// <param name="userId">Input parameter of stored procedure</param>
        /// <param name="newDepartmentId">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">Return value of the stored procedure</param>
        /// <returns>Amount of rows affected, if the database / routine doesn't surpress rowcounting.</returns>
        public static int CopyDepartments(System.Int32 companyId, System.Int32 departmentId, System.String departmentName, System.Int32 targetId, System.Int32 userId, ref System.Int32 newDepartmentId, ref System.Int32 returnValue, ref System.Int32 returnValue)
        {
            using(DataAccessAdapter adapter = new DataAccessAdapter())
            {
                return CopyDepartments(companyId, departmentId, departmentName, targetId, userId, ref newDepartmentId, ref returnValue, ref returnValue, adapter);
            }
        }

        
        /// <summary>
        /// Calls stored procedure 'CopyDepartments'.<br/><br/>
        /// 
        /// </summary>
        /// <param name="companyId">Input parameter of stored procedure</param>
        /// <param name="departmentId">Input parameter of stored procedure</param>
        /// <param name="departmentName">Input parameter of stored procedure</param>
        /// <param name="targetId">Input parameter of stored procedure</param>
        /// <param name="userId">Input parameter of stored procedure</param>
        /// <param name="newDepartmentId">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">InputOutput parameter of stored procedure</param>
        /// <param name="returnValue">Return value of the stored procedure</param>
        /// <param name="adapter">The DataAccessAdapter object to use for the call</param>
        /// <returns>Amount of rows affected, if the database / routine doesn't surpress rowcounting.</returns>
        public static int CopyDepartments(System.Int32 companyId, System.Int32 departmentId, System.String departmentName, System.Int32 targetId, System.Int32 userId, ref System.Int32 newDepartmentId, ref System.Int32 returnValue, ref System.Int32 returnValue, DataAccessAdapter adapter)
        {
            // create parameters. Add 1 to make room for the return value parameter.
            SqlParameter[] parameters = new SqlParameter[7 + 1];
            parameters[0] = new SqlParameter("@CompanyID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, companyId);
            parameters[1] = new SqlParameter("@DepartmentID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, departmentId);
            parameters[2] = new SqlParameter("@DepartmentName", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "",  DataRowVersion.Current, departmentName);
            parameters[3] = new SqlParameter("@TargetID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, targetId);
            parameters[4] = new SqlParameter("@UserID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, userId);
            parameters[5] = new SqlParameter("@NewDepartmentID", SqlDbType.Int, 0, ParameterDirection.InputOutput, true, 10, 0, "",  DataRowVersion.Current, newDepartmentId);
            parameters[6] = new SqlParameter("@ReturnValue", SqlDbType.Int, 0, ParameterDirection.InputOutput, true, 10, 0, "",  DataRowVersion.Current, returnValue);
            parameters[7] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "",  DataRowVersion.Current, returnValue);
            int toReturn = adapter.CallActionStoredProcedure("[qqest].[dbo].[CopyDepartments]", parameters);
            if(parameters[5].Value!=System.DBNull.Value)
            {
                newDepartmentId = (System.Int32)parameters[5].Value;
            }
            if(parameters[6].Value!=System.DBNull.Value)
            {
                returnValue = (System.Int32)parameters[6].Value;
            }
            
            returnValue = (int)parameters[7].Value;
            return toReturn;
        }

...not a big deal for me as I'll just ignore that stored procedure, but thought you'd at least like to know there are people out there naming their parameters the same as you. I should note that this may have also happend in the not beta version, but I am not planning on using LLBLGen on this database for production. This is a small project I'm doing that I'm using to learn the differences between Beta LLBLGen and !Beta LLBLGen.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39894
Joined: 17-Aug-2003
# Posted on: 09-May-2006 19:15:39   

This is also true in the current version indeed. The 'best' way to deal with this is to rename the parameter in the designer. I know this can be tedious, if there are a lot of procs. If that's the case, you should write a simple plugin to do this for you (has to be done once).

Frans Bouma | Lead developer LLBLGen Pro