Example #1
0
        /// <summary>
        /// Generates the name of an element according to the naming conventions configuration
        /// </summary>
        /// <param name="parentEntityType">The type of the parent entity</param>
        /// <param name="elementType">The type of the element</param>
        /// <param name="relationshipProperty">The property that represents the relationship</param>
        /// <returns>The element name</returns>
        public string ToElementTableName(Type parentEntityType, Type elementType, MemberInfo relationshipProperty)
        {
            string result = null;

            switch (namingConventions.ElementsTableNamingConvention)
            {
            case ElementsTableNamingConvention.ElementTypeName: result = ToTableName(elementType); break;

            case ElementsTableNamingConvention.PropertyName: result = ToTableName(relationshipProperty.Name); break;

            case ElementsTableNamingConvention.EntityNameElementName: result = ToTableName(string.Concat(parentEntityType.Name, elementType.Name)); break;

            case ElementsTableNamingConvention.EntityNamePropertyName: result = ToTableName(string.Concat(parentEntityType.Name, relationshipProperty.Name)); break;

            case ElementsTableNamingConvention.EntityName_ElementName: result = string.Format(ConventionFormats.RelationshipUnderscoreSeparated, ToTableName(parentEntityType), ToTableName(elementType)); break;

            case ElementsTableNamingConvention.EntityName_PropertyName: result = string.Format(ConventionFormats.RelationshipUnderscoreSeparated, ToTableName(parentEntityType), ToTableName(relationshipProperty.Name)); break;

            case ElementsTableNamingConvention.Custom:
            {
                if (namingConventions.ElementsCustomTableNamingConvention == null)
                {
                    throw new ConfigurationErrorsException(string.Format(ExceptionMessages.CustomConventionNotFound, typeof(ElementsTableNamingConvention).Name));
                }

                result = namingConventions.ElementsCustomTableNamingConvention(parentEntityType, elementType, relationshipProperty);
            }; break;
            }

            return(result);
        }