public static string BuildXmlClassComment(SchemaExplorer.CommandSchema command) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); builder.Append("\t\t/// <summary>\r\n"); builder.Append("\t\t/// Date Created:"); if(command != null) builder.Append(command.DateCreated); builder.Append("\r\n\t\t/// <remarks>"); builder.Append("\r\n\t\t/// "); if(command != null) builder.Append(command.Description); builder.Append("\r\n\t\t/// </remarks>\r\n"); builder.Append("\t\t/// </summary>"); return builder.ToString(); }
///<summary> /// Returns an array list of Child Collections of the object ///</summary> public System.Collections.ArrayList GetChildrenCollections(SchemaExplorer.TableSchema table, SchemaExplorer.TableSchemaCollection tables) { //System.Diagnostics.Debugger.Break(); //CleanUp if(CurrentTable != table.Name) { _collections.Clear(); _renderedChildren.Clear(); CurrentTable = table.Name; } if (_collections.Count > 0) return _collections; //Provides Informatoin about the foreign keys TableKeySchemaCollection fkeys = table.ForeignKeys; //Provides information about the indexes contained in the table. IndexSchemaCollection indexes = table.Indexes; TableKeySchemaCollection primaryKeyCollection = table.PrimaryKeys; foreach(TableKeySchema keyschema in primaryKeyCollection) { // add the relationship only if the linked table is part of the selected tables (ie: omit tables without primary key) if (!tables.Contains(keyschema.ForeignKeyTable.Owner, keyschema.ForeignKeyTable.Name)) { continue; } //Add 1-1 relations if(IsRelationOneToOne(keyschema)) { CollectionInfo collectionInfo = new CollectionInfo(); collectionInfo.PkColName = table.PrimaryKey.MemberColumns[0].Name; collectionInfo.PkIdxName = keyschema.Name; collectionInfo.PrimaryTable = table.Name; collectionInfo.SecondaryTable = keyschema.ForeignKeyTable.Name; collectionInfo.SecondaryTablePkColName = keyschema.ForeignKeyTable.PrimaryKey.MemberColumns[0].Name; collectionInfo.CollectionRelationshipType = RelationshipType.OneToOne; collectionInfo.CleanName = keyschema.ForeignKeyTable.Name;//GetClassName(keyschema.ForeignKeyTable.Name); collectionInfo.CollectionName = GetCollectionClassName(collectionInfo.CleanName); collectionInfo.CallParams = GetFunctionRelationshipCallParameters(keyschema.ForeignKeyMemberColumns); collectionInfo.GetByKeysName = "GetBy" + GetKeysName(keyschema.ForeignKeyMemberColumns); collectionInfo.TableKey = keyschema; _collections.Add(collectionInfo); } //Add 1-N,N-1 relations else { CollectionInfo collectionInfo = new CollectionInfo(); collectionInfo.PkColName = table.PrimaryKey.MemberColumns[0].Name; collectionInfo.PkIdxName = keyschema.Name; collectionInfo.PrimaryTable = table.Name; collectionInfo.SecondaryTable = keyschema.ForeignKeyTable.Name; collectionInfo.SecondaryTablePkColName = keyschema.ForeignKeyTable.PrimaryKey.MemberColumns[0].Name; collectionInfo.CollectionRelationshipType = RelationshipType.OneToMany; collectionInfo.CleanName = keyschema.ForeignKeyTable.Name; //GetClassName(keyschema.ForeignKeyTable.Name); collectionInfo.CollectionName = GetCollectionClassName(collectionInfo.CleanName); collectionInfo.CallParams = GetFunctionRelationshipCallParameters(table.PrimaryKey.MemberColumns); //collectionInfo.CallParams = GetFunctionRelationshipCallParameters(keyschema.ForeignKeyMemberColumns); collectionInfo.GetByKeysName = "GetBy" + GetKeysName(keyschema.ForeignKeyMemberColumns); collectionInfo.TableKey = keyschema; //collectionInfo.GetByKeysName = "GetBy" + GetKeysName(keyschema.ForeignKeyTable.PrimaryKey.MemberColumns); _collections.Add(collectionInfo); } } //Add N-N relations // TODO -> only if option is activated foreach(TableKeySchema key in primaryKeyCollection) { // Check that the key is related to a junction table and that this key relate a PK in this junction table if ( tables.Contains(key.ForeignKeyTable.Owner, key.ForeignKeyTable.Name) && IsJunctionTable(key.ForeignKeyTable) && IsJunctionKey(key)) { TableSchema junctionTable = key.ForeignKeyTable; // Search for the other(s) key(s) of the junction table' primary key foreach(TableKeySchema junctionTableKey in junctionTable.ForeignKeys) { if ( tables.Contains(junctionTableKey.ForeignKeyTable.Owner, junctionTableKey.ForeignKeyTable.Name) && IsJunctionKey(junctionTableKey) && junctionTableKey.Name != key.Name ) { TableSchema secondaryTable = junctionTableKey.PrimaryKeyTable; CollectionInfo collectionInfo = new CollectionInfo(); collectionInfo.PkColName = table.PrimaryKey.MemberColumns[0].Name; collectionInfo.PkIdxName = junctionTableKey.Name; collectionInfo.PrimaryTable = table.Name; collectionInfo.SecondaryTable = junctionTableKey.PrimaryKeyTable.Name; collectionInfo.SecondaryTablePkColName = junctionTableKey.PrimaryKeyTable.PrimaryKey.MemberColumns[0].Name; collectionInfo.JunctionTable = junctionTable.Name; collectionInfo.CollectionName = string.Format("{0}_From_{1}", GetCollectionClassName( collectionInfo.SecondaryTable), GetCleanName(collectionInfo.JunctionTable)); //GetManyToManyName(GetCollectionClassName( collectionInfo.SecondaryTable), collectionInfo.JunctionTable); collectionInfo.CollectionRelationshipType = RelationshipType.ManyToMany; collectionInfo.CallParams = "entity." + GetPropertyName(collectionInfo.PkColName); ///Find FK junc table key, used for loading scenarios if(junctionTable.PrimaryKey.MemberColumns[0] == junctionTableKey.ForeignKeyMemberColumns[0]) { collectionInfo.FkColName = junctionTable.PrimaryKey.MemberColumns[1].Name; } else { collectionInfo.FkColName = junctionTable.PrimaryKey.MemberColumns[0].Name; } collectionInfo.CallParams = "entity." + GetPropertyName(collectionInfo.PkColName); //collectionInfo.GetByKeysName = collectionInfo.PkColName + "From" + GetClassName(junctionTable.Name); collectionInfo.GetByKeysName = FKColumnName(key) + "From" + GetCleanName(junctionTable.Name); collectionInfo.TableKey = key; //GetManyToManyName(junctionTable.PrimaryKey.MemberColumns, collectionInfo.JunctionTable); //collectionInfo.GetByKeysName = GetManyToManyName(table.PrimaryKey.MemberColumns, GetClassName(junctionTable.Name));; collectionInfo.CleanName = string.Format("{0}From{1}", GetCleanName(collectionInfo.SecondaryTable), GetCleanName(junctionTable.Name)); //GetManyToManyName(collectionInfo.SecondaryTable, junctionTable.Name); _collections.Add(collectionInfo); } } } }// end N-N relations return _collections; }