コード例 #1
0
        public void TestIntermediateClass()
        {
            TableNode tn;

            PrepareOrderDetails(out tn);
            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.MappedAsIntermediateClass);
            TreeNodeCollection nodes = ApplicationController.Instance.DatabaseNode.Nodes;
            object             o     = FindNode(nodes, tn.Text);

            Assertion.AssertNotNull("Intermediate Class '" + tn.Text + "' not found", o);
            Assertion.AssertSame("Node should be the same table node", tn, o);
            RelationNode rn = tn.FindRelationNode("OrderID", "Orders");

            Assertion.AssertNotNull("Relation to Orders should be there", rn);
            Assertion.Assert("Wrong relation type", rn.Relation is FkRelation);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNotNull("Relation to Products should be there", rn);
            Assertion.Assert("Wrong relation type", rn.Relation is FkRelation);

            TableNode tnOrders = (TableNode)FindNode(nodes, "Orders");

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNotNull("OrderID relation not found", rn);
            TableNode tnProducts = (TableNode)FindNode(nodes, "Products");

//			foreach(NDOTreeNode trn in tnProducts.Nodes)
//			{
//				RelationNode rn2 = trn as RelationNode;
//				if (rn2 != null)
//				{
//					Debug.WriteLine(rn2.Text + " " + rn2.Relation.GetType().Name);
//					ForeignFkRelation fkr = rn2.Relation as ForeignFkRelation;
//					if (fkr != null)
//						Debug.WriteLine(fkr.RelatedTable);
//				}
//			}
            rn = tnProducts.FindRelationNode("ProductID", "Order Details");
            Assertion.AssertNull("Relation is directed", rn);
            tn.UnmapIntermediateClass(null, EventArgs.Empty);

            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.NotMapped);

            rn = tn.FindRelationNode("OrderID", "Orders");
            Assertion.AssertNull("Relation to Orders should be removed", rn);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNull("Relation to Products should be removed", rn);

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNull("Relation should be removed", rn);
        }
コード例 #2
0
 public void UnmapIntermediateClass(TableNode tn)
 {
     foreach (NDOTreeNode trn in tn.Nodes)
     {
         RelationNode rn = trn as RelationNode;
         if (rn == null)
         {
             continue;
         }
         rn.Remove();
         FkRelation fkRelation = rn.Relation as FkRelation;
         if (fkRelation != null)
         {
             if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
             {
                 TableNode    relTn        = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                 RelationNode nodeToRemove = relTn.FindRelationNode(rn.Text, tn.Text);
                 if (nodeToRemove != null)
                 {
                     nodeToRemove.Remove();
                 }
             }
         }
     }
 }
コード例 #3
0
        public void TestIntermediateClassRemove2()
        {
            TableNode tn;

            PrepareOrderDetails(out tn);

            TreeNodeCollection nodes = ApplicationController.Instance.DatabaseNode.Nodes;

            TableNode tnOrders   = (TableNode)FindNode(nodes, "Orders");
            TableNode tnProducts = (TableNode)FindNode(nodes, "Products");

            tnProducts.UnmapClass(null, EventArgs.Empty);

            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.NotMapped);

            RelationNode rn = tn.FindRelationNode("OrderID", "Orders");

            Assertion.AssertNull("Relation to Orders should be removed", rn);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNull("Relation to Products should be removed", rn);

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNull("Relation should be removed", rn);
//			ApplicationController.Instance.GenerateAssembly();
        }
コード例 #4
0
        public void DeleteRelation(RelationNode relationNode)
        {
            FkRelation fkRelation = relationNode.Relation as FkRelation;
            TableNode  parentNode = null;

            if (fkRelation == null)
            {
                ForeignFkRelation ffkrel = relationNode.Relation as ForeignFkRelation;
                if (ffkrel == null)
                {
                    return;
                }
                parentNode   = (TableNode)this.databaseNode.FindNode(ffkrel.RelatedTable, typeof(TableNode));
                relationNode = parentNode.FindRelationNode(relationNode.Text, relationNode.Parent.Text);                //(RelationNode) parentNode.FindNode(relationNode.Text, typeof(RelationNode));
                fkRelation   = (FkRelation)relationNode.Relation;
                if (parentNode.Table.MappingType == TableMappingType.MappedAsIntermediateClass)
                {
                    parentNode.UnmapIntermediateClass(null, EventArgs.Empty);
                    return;
                }
            }
            else
            {
                parentNode = (TableNode)relationNode.Parent;
            }

            //parentNode.Nodes. Remove(relationNode);
            relationNode.Remove();
            parentNode.Nodes.Add(relationNode.OriginalColumnNode);

            Debug.Assert(fkRelation != null);
            if (fkRelation != null)
            {
                if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
                {
                    TableNode    tn           = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                    RelationNode nodeToRemove = tn.FindRelationNode(relationNode.Text, parentNode.Text);
                    if (nodeToRemove != null)
                    {
                        nodeToRemove.Remove();
                    }
                }
            }
        }