Exemple #1
0
        /// <summary>
        /// Generates the name of a many to many table according the naming conventions configuration
        /// </summary>
        /// <param name="firstEntityType">The type of the first entity of the relationship</param>
        /// <param name="secondEntityType">The type of the second entity of the relationship</param>
        /// <returns>The generated table name</returns>
        public string ToManyToManyTableName(Type firstEntityType, Type secondEntityType)
        {
            string result     = null;
            Type   firstType  = firstEntityType;
            Type   secondType = secondEntityType;

            if (string.Compare(firstEntityType.Name, secondEntityType.Name) > 0)
            {
                firstType  = secondEntityType;
                secondType = firstEntityType;
            }

            switch (namingConventions.ManyToManyTableNamingConvention)
            {
            case ManyToManyTableNamingConvention.FirstTableNameToSecondTableName: result = ToTableName(string.Format(ConventionFormats.ManyToManyToSeparator, firstType.Name, secondType.Name)); break;

            case ManyToManyTableNamingConvention.FirstTableNameSecondTableName: result = ToTableName(string.Format(ConventionFormats.ManyToManyNoSeparator, firstType.Name, secondType.Name)); break;

            case ManyToManyTableNamingConvention.FirstTableName_SecondTableName: result = string.Format(ConventionFormats.ManyToManyUndescoreSeparator, ToTableName(firstType), ToTableName(secondType)); break;

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

                result = namingConventions.ManyToManyCustomTableNamingConvention(firstType, secondType);
            }; break;
            }

            return(result);
        }