Ejemplo n.º 1
0
        protected void Check()
        {
            string entity;
            string relatedEntity;

            if (this is ManyToManyRelationship)
            {
                ManyToManyRelationship manyToManyRelationship = this as ManyToManyRelationship;
                entity        = manyToManyRelationship.OneToManyRelationship.Entity;
                relatedEntity = manyToManyRelationship.ManyToOneRelationship.RelatedEntity;
                if (manyToManyRelationship.OneToManyRelationship.RelatedEntity != manyToManyRelationship.ManyToOneRelationship.Entity)
                {
                    throw new SchemaException(SchemaMessages.RelationshipsNonConnected);
                }
            }
            else if (this is PlainRelationship)
            {
                PlainRelationship plainRelationship = this as PlainRelationship;
                entity        = plainRelationship.DirectRelationships[0].Entity;
                relatedEntity = plainRelationship.DirectRelationships[plainRelationship.DirectRelationships.Length - 1].RelatedEntity;
            }
            else //if (this is Relationship)
            {
                entity        = this.DirectRelationships[0].Entity;
                relatedEntity = this.DirectRelationships[this.DirectRelationships.Length - 1].RelatedEntity;
            }
            if (Entity != entity)
            {
                throw new SchemaException(string.Format(SchemaMessages.ConflictingEntities, Entity, entity));
            }
            if (RelatedEntity != relatedEntity)
            {
                throw new SchemaException(string.Format(SchemaMessages.ConflictingRelatedEntities, RelatedEntity, relatedEntity));
            }
        }
Ejemplo n.º 2
0
        // ManyToManyRelationship or PlainRelationship
        public XElement ToXml()
        {
            if (this is ManyToManyRelationship)
            {
                ManyToManyRelationship relationship = this as ManyToManyRelationship;

                XElement relationshipSchema = new XElement(SchemaVocab.Relationship);
                relationshipSchema.SetAttributeValue(SchemaVocab.Name, relationship.Name);

                relationshipSchema.SetAttributeValue(SchemaVocab.Type, SchemaVocab.ManyToMany);
                relationshipSchema.SetAttributeValue(SchemaVocab.Entity, relationship.Entity);
                relationshipSchema.SetAttributeValue(SchemaVocab.RelatedEntity, relationship.RelatedEntity);

                relationshipSchema.Add(PlainRelationshipToXml(relationship.OneToManyRelationship).Elements(SchemaVocab.Relationship));
                relationshipSchema.Add(PlainRelationshipToXml(relationship.ManyToOneRelationship).Elements(SchemaVocab.Relationship));

                return(relationshipSchema);
            }

            return(PlainRelationshipToXml(this as PlainRelationship));
        }
Ejemplo n.º 3
0
        private static ManyToManyRelationship CreateManyToManyRelationship(XElement relationshipSchema)
        {
            string entity        = relationshipSchema.Attribute(SchemaVocab.Entity).Value;
            string relatedEntity = relationshipSchema.Attribute(SchemaVocab.RelatedEntity).Value;

            XElement oneToManySchema = new XElement(SchemaVocab.Relationship);

            oneToManySchema.SetAttributeValue(SchemaVocab.Type, SchemaVocab.OneToMany);
            oneToManySchema.SetAttributeValue(SchemaVocab.Entity, entity);
            oneToManySchema.SetAttributeValue(SchemaVocab.RelatedEntity, string.Empty);
            oneToManySchema.Add(relationshipSchema.Elements(SchemaVocab.Relationship).Where(x => x.Attribute(SchemaVocab.Type).Value == SchemaVocab.OneToMany));
            OneToManyRelationship oneToManyRelationship = (OneToManyRelationship)CreatePlainRelationship(oneToManySchema);

            oneToManySchema.SetAttributeValue(SchemaVocab.RelatedEntity,
                                              oneToManyRelationship.DirectRelationships[oneToManyRelationship.DirectRelationships.Length - 1].RelatedEntity);

            XElement manyToOneSchema = new XElement(SchemaVocab.Relationship);

            manyToOneSchema.SetAttributeValue(SchemaVocab.Type, SchemaVocab.ManyToOne);
            manyToOneSchema.SetAttributeValue(SchemaVocab.Entity, string.Empty);
            manyToOneSchema.SetAttributeValue(SchemaVocab.RelatedEntity, relatedEntity);
            manyToOneSchema.Add(relationshipSchema.Elements(SchemaVocab.Relationship).Where(x => x.Attribute(SchemaVocab.Type).Value == SchemaVocab.ManyToOne));
            ManyToOneRelationship manyToOneRelationship = (ManyToOneRelationship)CreatePlainRelationship(manyToOneSchema);

            manyToOneSchema.SetAttributeValue(SchemaVocab.Entity, manyToOneRelationship.DirectRelationships[0].Entity);

            ManyToManyRelationship relationship = new ManyToManyRelationship(oneToManyRelationship, manyToOneRelationship);

            XAttribute attr = relationshipSchema.Attribute(SchemaVocab.Name);

            if (attr != null)
            {
                relationship.Name = attr.Value;
            }

            return(relationship);
        }
Ejemplo n.º 4
0
 private static ManyToManyRelationship Reverse(ManyToManyRelationship relationship)
 {
     return(new ManyToManyRelationship(
                (OneToManyRelationship)relationship.ManyToOneRelationship.Reverse(),
                (ManyToOneRelationship)relationship.OneToManyRelationship.Reverse()));
 }