コード例 #1
0
        public Relationship CreateRelationshipTo(ITable targetTable)
        {
            var newRel = new RelationshipImpl();

            newRel.PrimaryTable = this;
            newRel.ForeignTable = targetTable;

            newRel.PrimaryKey = new Key(Guid.NewGuid().ToString())
            {
                IsUserDefined = true, Keytype = DatabaseKeyType.Primary
            };
            newRel.ForeignKey = new Key(Guid.NewGuid().ToString())
            {
                IsUserDefined = true, Keytype = DatabaseKeyType.Foreign
            };

            AddKey(newRel.PrimaryKey);
            targetTable.AddKey(newRel.ForeignKey);

            newRel.PrimaryKey.Parent = this;
            newRel.ForeignKey.Parent = targetTable;

            newRel.Database = Database;
            Database.AddRelationship(newRel);

            AddRelationship(newRel);
            targetTable.AddRelationship(newRel);

            return(newRel);
        }
コード例 #2
0
        public Relationship Clone()
        {
            RelationshipImpl relationship = new RelationshipImpl();

            CopyInto(relationship);

            return(relationship);
        }
コード例 #3
0
        public Relationship DeserialiseRelationship(XmlNode node, IDatabase database)
        {
            NodeProcessor proc = new NodeProcessor(node);

            var rel = new RelationshipImpl();

            rel.Identifier = proc.Attributes.GetGuid("identifier");
            rel.Name       = proc.GetString("Name");

            ITable table1 = database.GetTable(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
            ITable table2 = database.GetTable(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));

            if (table1 == null)
            {
                table1 = database.GetView(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
            }

            if (table2 == null)
            {
                table2 = database.GetView(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));
            }

            if (table1 == null || table2 == null)
            {
                return(null);
            }

            var key1 = table1.GetKey(proc.GetString("PrimaryKey"));
            var key2 = table2.GetKey(proc.GetString("ForeignKey"));

            if (key1 == null || key2 == null)
            {
                return(null);                // The foreign key has probably been removed
            }
            if (key1.Keytype == DatabaseKeyType.Foreign)
            {
                // The keys are around the wrong way.
                var tempKey = key2;
                key2 = key1;
                key1 = tempKey;

                var tempTable = table2;
                table2 = table1;
                table1 = tempTable;
            }

            rel.AddThisTo(table1, table2);
            rel.PrimaryKey         = key1;
            rel.ForeignKey         = key2;
            rel.PrimaryCardinality = rel.ForeignKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.ForeignCardinality = rel.PrimaryKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.Database           = database;

            return(rel);
        }
コード例 #4
0
 public bool Equals(RelationshipImpl other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(base.Equals(other) && Equals(other.PrimaryTable, PrimaryTable) && Equals(other.ForeignTable, ForeignTable) && Equals(other.PrimaryKey, PrimaryKey) && Equals(other.ForeignKey, ForeignKey));
 }
コード例 #5
0
        public Relationship CreateRelationshipUsing(IKey thisKey, IKey otherTableKey)
        {
            var newRel = new RelationshipImpl();

            newRel.PrimaryTable = this;
            newRel.ForeignTable = otherTableKey.Parent;

            newRel.PrimaryKey = thisKey;
            newRel.ForeignKey = otherTableKey;

            AddRelationship(newRel);
            otherTableKey.Parent.AddRelationship(newRel);

            newRel.Database = Database;
            Database.AddRelationship(newRel);

            return(newRel);
        }