Esempio n. 1
0
        // Specialty(DepartmentId)-Department(Id, CollegeId)-College(Id, UniversityId)-University(Id)
        protected static T Create <T>(string value) where T : Relationship
        {
            Relationship relationship;

            if (typeof(T) == typeof(ManyToOneRelationship))
            {
                IEnumerable <ManyToOneDirectRelationship> rels = GenerateDirectRelationships <ManyToOneDirectRelationship>(value);
                relationship = new ManyToOneRelationship(rels);
            }
            else if (typeof(T) == typeof(OneToManyRelationship))
            {
                IEnumerable <OneToManyDirectRelationship> rels = GenerateDirectRelationships <OneToManyDirectRelationship>(value);
                relationship = new OneToManyRelationship(rels);
            }
            else if (typeof(T) == typeof(OneToOneRelationship))
            {
                IEnumerable <OneToOneDirectRelationship> rels = GenerateDirectRelationships <OneToOneDirectRelationship>(value);
                relationship = new OneToOneRelationship(rels);
            }
            else
            {
                IEnumerable <DirectRelationship> rels = GenerateDirectRelationships <DirectRelationship>(value);
                relationship = new Relationship(rels);
            }
            return(relationship as T);
        }
Esempio n. 2
0
        public static ExtendProperty GenerateExtendProperty(string property, string entity, XElement schema)
        {
            XElement extendPropertySchema = schema.GenerateExtendPropertySchema(entity, property);

            XAttribute            entityAttr       = extendPropertySchema.Attribute(SchemaVocab.Entity);
            XAttribute            propertyAttr     = extendPropertySchema.Attribute(SchemaVocab.Property);
            XAttribute            relationshipAttr = extendPropertySchema.Attribute(SchemaVocab.Relationship);
            ManyToOneRelationship relationship     = new ManyToOneRelationship(relationshipAttr.Value, entity, entityAttr.Value, schema);

            return(new ExtendProperty(property, entityAttr.Value, propertyAttr.Value, relationship));
        }
Esempio n. 3
0
        public static FieldProperty Create(string property, string entity, XElement schema)
        {
            XElement entitySchema   = schema.GetEntitySchema(entity);
            XElement propertySchema = entitySchema.Elements(SchemaVocab.Property).FirstOrDefault(x => x.Attribute(SchemaVocab.Name).Value == property);

            XAttribute collectionattr = propertySchema.Attribute(SchemaVocab.Collection);

            if (collectionattr != null)
            {
                throw new SyntaxErrorException(string.Format(ErrorMessages.NonFieldProperty, property, entity));
            }

            FieldProperty oProperty;

            XAttribute entityAttr   = propertySchema.Attribute(SchemaVocab.Entity);
            XAttribute propertyAttr = propertySchema.Attribute(SchemaVocab.Property);

            if (entityAttr == null)
            {
                XAttribute columnAttr   = propertySchema.Attribute(SchemaVocab.Column);
                XAttribute dataTypeAttr = propertySchema.Attribute(SchemaVocab.DataType);
                if (columnAttr == null || dataTypeAttr == null)
                {
                    throw new SyntaxErrorException(string.Format(ErrorMessages.NonNativeProperty, property, entity));
                }

                oProperty = new NativeProperty(property);
            }
            else
            {
                if (propertyAttr == null)
                {
                    throw new SyntaxErrorException(string.Format(ErrorMessages.NonExtendProperty, property, entity));
                }

                XAttribute relationshipAttr = propertySchema.Attribute(SchemaVocab.Relationship);
                if (relationshipAttr == null)
                {
                    throw new SchemaException(string.Format(SchemaMessages.RelationshipRequired, property, entity));
                }

                ManyToOneRelationship relationship = new ManyToOneRelationship(relationshipAttr.Value, entity, entityAttr.Value, schema);
                oProperty = new ExtendProperty(property, entityAttr.Value, propertyAttr.Value, relationship);
            }

            return(oProperty);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private static IEnumerable <DirectRelationship> GetDirectRelationships(OneToManyRelationship oneToManyRelationship, ManyToOneRelationship manyToOneRelationship)
        {
            List <DirectRelationship> list = new List <DirectRelationship>(oneToManyRelationship.DirectRelationships);

            list.AddRange(manyToOneRelationship.DirectRelationships);
            return(list);
        }
Esempio n. 6
0
 public ManyToManyRelationship(OneToManyRelationship oneToManyRelationship, ManyToOneRelationship manyToOneRelationship)
     : base(oneToManyRelationship.Entity, manyToOneRelationship.RelatedEntity, GetDirectRelationships(oneToManyRelationship, manyToOneRelationship))
 {
     OneToManyRelationship = oneToManyRelationship;
     ManyToOneRelationship = manyToOneRelationship;
 }
Esempio n. 7
0
        private static PlainRelationship CreatePlainRelationship(XElement relationshipSchema)
        {
            PlainRelationship relationship;

            if (relationshipSchema.Elements(SchemaVocab.Relationship).Any())
            {
                string type          = relationshipSchema.Attribute(SchemaVocab.Type).Value;
                string entity        = relationshipSchema.Attribute(SchemaVocab.Entity).Value;
                string relatedEntity = relationshipSchema.Attribute(SchemaVocab.RelatedEntity).Value;

                List <DirectRelationship> relList = new List <DirectRelationship>();
                foreach (XElement xDirectRelationship in relationshipSchema.Elements(SchemaVocab.Relationship))
                {
                    DirectRelationship rel = DirectRelationship.Create(xDirectRelationship, type);
                    relList.Add(rel);
                }
                IEnumerable <DirectRelationship> rels = DirectRelationship.Connect(relList);

                switch (type)
                {
                case SchemaVocab.ManyToOne:
                    relationship = new ManyToOneRelationship(entity, relatedEntity, rels);
                    break;

                case SchemaVocab.OneToMany:
                    relationship = new OneToManyRelationship(entity, relatedEntity, rels);
                    break;

                case SchemaVocab.OneToOne:
                    relationship = new OneToOneRelationship(entity, relatedEntity, rels);
                    break;

                default:
                    throw new NotSupportedException(type);
                }
            }
            else
            {
                DirectRelationship        rel     = DirectRelationship.Create(relationshipSchema);
                List <DirectRelationship> relList = new List <DirectRelationship>()
                {
                    rel
                };
                if (rel is ManyToOneDirectRelationship)
                {
                    relationship = new ManyToOneRelationship(rel.Entity, rel.RelatedEntity, relList);
                }
                else if (rel is OneToManyDirectRelationship)
                {
                    relationship = new OneToManyRelationship(rel.Entity, rel.RelatedEntity, relList);
                }
                else if (rel is OneToOneDirectRelationship)
                {
                    relationship = new OneToOneRelationship(rel.Entity, rel.RelatedEntity, relList);
                }
                else
                {
                    throw new NotSupportedException(rel.GetType().ToString()); // never
                }
            }

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

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

            return(relationship);
        }
Esempio n. 8
0
 public ExtendProperty(string name, string entity, string property, ManyToOneRelationship relationship) : base(name)
 {
     Entity       = entity;
     Property     = property;
     Relationship = relationship;
 }
Esempio n. 9
0
 public OneToManyRelationship(ManyToOneRelationship relationship)
     : base(relationship.RelatedEntity, relationship.Entity, ((OneToManyRelationship)relationship.Reverse()).DirectRelationships)
 {
 }