예제 #1
0
        /// <summary>Gets the ObjectPropertyToParameterNameMapping[] for the given object type and procedure.</summary>
        /// <typeparam name="T">Type of object the procedure parameters are mapping to.</typeparam>
        /// <param name="procedureName">Left side of sql stored procedure [schema].[PROCEDURE_NAME].</param>
        public static ObjectPropertyToParameterNameMapping[] GetParameterMapping <T>(string procedureName)
        {
            string mappingName = $"{procedureName}].T{typeof(T).ToString()}";

            if (!_objectPropertyToParameterNameMappings.ContainsKey(mappingName))
            {
                PropertyInfo[] properties = typeof(T).GetProperties();
                Procedure      proc       = _procedures[procedureName];

                List <ObjectPropertyToParameterNameMapping> mappings = new List <ObjectPropertyToParameterNameMapping>();

                for (int idx = 0, len = properties.Length; idx != len; idx++)
                {
                    PropertyInfo property      = properties[idx];
                    string       parameterName = $"@{property.Name.ToUnderscore()}";
                    if (proc.ContainsParameter(parameterName))
                    {
                        mappings.Add(new ObjectPropertyToParameterNameMapping(parameterName, property));
                    }
                }
                _objectPropertyToParameterNameMappings.Add(mappingName, mappings.ToArray());
            }
            return(_objectPropertyToParameterNameMappings[mappingName]);
        }