private static void FixDuplicateName(ICollection <string> tableNames, DatabaseTable table) { var netName = table.NetName; if (!tableNames.Contains(netName)) { return; } //first we try to add the schema as a prefix (eg DboCategory). var schemaOwner = NameFixer.ToPascalCase(table.SchemaOwner); var name = schemaOwner + netName; if (!tableNames.Contains(name)) { table.NetName = name; return; } //let's try suffixes- just count up to 100, and if we find a free one, use it for (var i = 0; i < 100; i++) { name = netName + "1"; if (!tableNames.Contains(name)) { table.NetName = name; return; } } }
/// <summary> /// Translates the namedObject's Name to a code-friendly name /// </summary> /// <param name="namedObject">The named object.</param> /// <returns></returns> public virtual string Name(INamedObject namedObject) { var name = NameFixer.ToPascalCase(namedObject.Name); var column = namedObject as DatabaseColumn; if (column != null) { //if it's a foreign key (CategoryId) if (column.IsForeignKey && name.EndsWith("Id", StringComparison.OrdinalIgnoreCase) && name.Length > 2) { //remove the "Id" - it's just a "Category" name = name.Substring(0, name.Length - 2); } //member name cannot be same as class name if (name == column.Table.NetName) { name += "Property"; } } return(name); }