void AddRelations(TableNode tn, NDO.Mapping.Class cl) { foreach (RelationNode rn in tn.RelationNodes) { Relation rel = rn.Relation; // This is for FkRelations, which must exist as entries in the // tree in order to delete the relation mapping. if (rel.RelationDirection == RelationDirection.DirectedToMe) { return; } if (rn.RelatedTableNode.Table.Skipped) { continue; } NDO.Mapping.Relation r = cl.AddStandardRelation(rel.FieldName, rn.RelatedTableNode.Table.Namespace + "." + rn.RelatedTableNode.Table.ClassName, rel.IsElement, string.Empty, false, false, null); r.RelationName = rel.RelationName; ForeignIntermediateTableRelation fitr = rel as ForeignIntermediateTableRelation; NDO.Mapping.ForeignKeyColumn fkColumn = (NDO.Mapping.ForeignKeyColumn)r.ForeignKeyColumns.First(); if (fitr == null) { fkColumn.Name = rn.Text; } else { fkColumn.Name = fitr.ForeignKeyColumnName; NDO.Mapping.MappingTable mtable = new NDO.Mapping.MappingTable(r); r.MappingTable = mtable; NDO.Mapping.ForeignKeyColumn cfkColumn = mtable.NewForeignKeyColumn(); cfkColumn.Name = fitr.ChildForeignKeyColumnName; mtable.ConnectionId = cl.ConnectionId; if (((DatabaseNode)tn.Parent).Database.OwnerName != string.Empty) { mtable.TableName = ((DatabaseNode)tn.Parent).Database.OwnerName + "." + fitr.TableName; } else { mtable.TableName = fitr.TableName; } } } }
public void MapIntermediateTable(TableNode tn) { IntermediateTable it = new IntermediateTable(tn.Text); IntermediateTableNode itn = new IntermediateTableNode(it, tn); IList tableNodes = databaseNode.TableNodes; tableNodes.Remove(tn); IntermediateTableWizardModel model = new IntermediateTableWizardModel(itn, tableNodes); IWizardController controller = ApplicationController.wizardControllerFactory.Create ("IntermediateTableWizController", "IntTblWiz", "Intermediate Table Wizard"); //controller.FrameSize = new Size(544, 416); DialogResult r = controller.Run(model); if (r == DialogResult.OK) { DatabaseNode parent = (DatabaseNode)tn.Parent; //tn.Parent.Nodes. Remove(tn); int index = parent.Nodes.IndexOf(tn); tn.Remove(); tn.Parent.Nodes.Insert(index, itn); itn.TreeView.SelectedNode = itn; itn.Nodes.Add(tn); // This ensures persisting the column nodes with file/save. RelatedTableInfo rti0 = it[0]; RelatedTableInfo rti1 = it[1]; TableNode relTn0 = null; TableNode relTn1 = null; RelationNode relNode0 = null; RelationNode relNode1 = null; foreach (TableNode loopTn in tableNodes) { if (loopTn.Text == rti0.Table) { relTn0 = loopTn; if (rti0.RelationDirection != RelationDirection.DirectedToMe) { ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti0, tn.Text); relNode0 = new RelationNode(fitr, relTn0); relTn0.Nodes.Add(relNode0); } } if (loopTn.Text == rti1.Table) { relTn1 = loopTn; if (rti1.RelationDirection != RelationDirection.DirectedToMe) { ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti1, tn.Text); relNode1 = new RelationNode(fitr, relTn1); relTn1.Nodes.Add(relNode1); } } } if (relNode0 != null) { relNode0.RelatedTableNode = relTn1; } if (relNode1 != null) { relNode1.RelatedTableNode = relTn0; } } }