/// <summary> /// Generates the name of the foreign key column name for a many to many relationship according the naming conventions configuration /// </summary> /// <param name="foreignKeyEntityType">The foreign key entity type</param> /// <param name="primaryKeyEntityType">The primary key entity</param> /// <param name="foreignKeyProperty">The foreign key property</param> /// <returns>The generated foreign key name</returns> public string ToManyToManyForeignKeyName(Type foreignKeyEntityType, Type primaryKeyEntityType, Type targetType, MemberInfo foreignKeyProperty) { string result = null; string foreignKeyEntityName = ToManyToManyTableName(foreignKeyEntityType, primaryKeyEntityType); switch (namingConventions.ForeignKeyNamingConvention) { case ForeignKeyNamingConvention.FK_FKTable_PKTable: result = ToConstraintName(string.Format(ConventionFormats.ForeignKeySourceTarget, foreignKeyEntityName, targetType.Name)); break; case ForeignKeyNamingConvention.FK_FKTable_PKTable_FKColumn: result = ToConstraintName(string.Format(ConventionFormats.ForeignKeySourceTargetKey, foreignKeyEntityName, targetType.Name, foreignKeyProperty.Name)); break; case ForeignKeyNamingConvention.FKTable_PKTable_FK: result = ToConstraintName(string.Format(ConventionFormats.ForeignKeySourceTargetSuffix, foreignKeyEntityName, targetType.Name)); break; case ForeignKeyNamingConvention.FKTable_PKTable_FKColumn_FK: result = ToConstraintName(string.Format(ConventionFormats.ForeignKeySourceTargetKeySuffix, foreignKeyEntityName, targetType.Name, foreignKeyProperty.Name)); break; case ForeignKeyNamingConvention.Custom: { if (namingConventions.ForeignKeyCustomNamingConvention == null) { throw new ConfigurationErrorsException(string.Format(ExceptionMessages.CustomConventionNotFound, typeof(ForeignKeyNamingConvention).Name)); } result = namingConventions.ForeignKeyCustomNamingConvention(foreignKeyEntityType, primaryKeyEntityType, targetType, foreignKeyProperty); }; break; } return(result); }