private List <Relationship> FindRelationship(Type instanceType, RelationshipKind kind)
        {
            List <Relationship> oneToOneRelationships = new List <Relationship>();

            PropertyInfo[] propertiesArray = DataMapper.GetTypeProperties(instanceType);

            Type attr = kind switch
            {
                RelationshipKind.OneToOne => typeof(OneToOneAttribute),
                RelationshipKind.OneToMany => typeof(OneToManyAttribute),
                RelationshipKind.ManyToMany => typeof(ManyToManyAttribute),
                _ => null,
            };

            foreach (var property in propertiesArray)
            {
                Object[] attributes = property.GetCustomAttributes(attr, false);

                if (attributes.Length != 0)
                {
                    Relationship oneToOneRelationship = new Relationship(instanceType, property, kind);
                    oneToOneRelationships.Add(oneToOneRelationship);
                }
            }

            return(oneToOneRelationships);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceRelationship"/> class.
 /// </summary>
 /// <param name="name">The name of the reference on the resource that defines the relationship.</param>
 /// <param name="urlPath">
 /// The url path of this relationship relative to the resource url that holds
 /// the relationship.
 /// </param>
 /// <param name="kind">The kind of relationship.</param>
 /// <param name="relationshipResource">The specification of the related resource.</param>
 protected ResourceRelationship(
     string name,
     string urlPath,
     RelationshipKind kind,
     ApiResource relationshipResource)
 {
     Name = name.ToDashed();
     UrlPath = urlPath.ToDashed();
     RelatedResource = relationshipResource;
     Kind = kind;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceRelationship"/> class.
 /// </summary>
 /// <param name="name">The name of the reference on the resource that defines the relationship.</param>
 /// <param name="urlPath">
 /// The url path of this relationship relative to the resource url that holds
 /// the relationship.
 /// </param>
 /// <param name="kind">The kind of relationship.</param>
 /// <param name="relationshipResource">The specification of the related resource.</param>
 protected ResourceRelationship(
     string name,
     string urlPath,
     RelationshipKind kind,
     ApiResource relationshipResource)
 {
     Name            = name.ToDashed();
     UrlPath         = urlPath.ToDashed();
     RelatedResource = relationshipResource;
     Kind            = kind;
 }
Example #4
0
    public virtual void AddChild(Child child, RelationshipKind relationshipKind)
    {
        var relationship = new ParentChildRelationship()
        {
            Parent           = this,
            Child            = child,
            RelationshipKind = relationshipKind
        };

        this._children.Add(relationship);
        child.AddParent(relationship);
    }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceRelationship"/> class.
 /// </summary>
 /// <param name="name">The name of the reference on the resource that defines the relationship.</param>
 /// <param name="urlPath">
 /// The url path of this relationship relative to the resource url that holds
 /// the relationship.
 /// </param>
 /// <param name="kind">The kind of relationship.</param>
 /// <param name="relationshipResource">The specification of the related resource.</param>
 /// <param name="withLinks">The defined <see cref="LinkType"/> to be generated for this relationship.</param>
 protected ResourceRelationship(
     string name,
     string urlPath,
     RelationshipKind kind,
     ApiResource relationshipResource,
     LinkType withLinks)
 {
     Name            = name.ToDashed();
     PropertyName    = name.ToPascalCase();
     UrlPath         = urlPath.ToDashed();
     RelatedResource = relationshipResource;
     Kind            = kind;
     LinkType        = withLinks;
 }
Example #6
0
        /// <summary>
        /// Construct a Relationship object
        /// </summary>
        /// <param name="parent">the parent</param>
        /// <param name="kind">the kind of relationship</param>
        public Relationship(Schema parent, RelationshipKind kind)
        : base(parent)
        {
            RelationshipKind = kind;

            if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
            {
                _isForeignKey = false;
                OtherContent.Add(Schema.SchemaSource);
            }
            else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
            {
                _isForeignKey = true;
            }
        }
Example #7
0
        /// <summary>
        /// Construct a Relationship object
        /// </summary>
        /// <param name="parent">the parent</param>
        /// <param name="kind">the kind of relationship</param>
        public Relationship(Schema parent, RelationshipKind kind)
            : base(parent)
        {
            RelationshipKind = kind;

            if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
            {
                _isForeignKey = false;
                OtherContent.Add(Schema.SchemaSource);
            }
            else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
            {
                _isForeignKey = true;
            }
        }
Example #8
0
 public Relationship(Schema parent, RelationshipKind kind)
     : base(parent)
 {
     this.RelationshipKind = kind;
     if (this.Schema.DataModel == SchemaDataModelOption.EntityDataModel)
     {
         this._isForeignKey = false;
         this.OtherContent.Add(this.Schema.SchemaSource);
     }
     else
     {
         if (this.Schema.DataModel != SchemaDataModelOption.ProviderDataModel)
         {
             return;
         }
         this._isForeignKey = true;
     }
 }
Example #9
0
        /// <summary>
        /// Handle the Action attribute
        /// </summary>
        /// <param name="reader">reader positioned at Action attribute</param>
        private void HandleActionAttribute(XmlReader reader)
        {
            Debug.Assert(reader != null);

            RelationshipKind relationshipKind = ParentElement.ParentElement.RelationshipKind;

            switch (reader.Value.Trim())
            {
            case "None":
                Action = Action.None;
                break;

            case "Cascade":
                Action = Action.Cascade;
                break;

            default:
                AddError(ErrorCode.InvalidAction, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidAction(reader.Value, ParentElement.FQName));
                break;
            }
        }
Example #10
0
 internal ResourceRelationship(string name, string urlPath, RelationshipKind kind, T resource)
     : base(name, urlPath, kind, resource)
 {
 }
Example #11
0
 public ClassToClassRelationship(string value, IClassEntity left, IClassEntity right, RelationshipKind kind)
     : base(2)
 {
     base.Value       = value;
     base.Entities[0] = left;
     base.Entities[1] = right;
     base.Kind        = kind;
     base.GenerateIdentity();
 }
Example #12
0
 internal ResourceRelationship(string name, string idPropertyName, string urlPath, RelationshipKind kind, T resource, LinkType withLinks)
     : base(name, idPropertyName, urlPath, kind, resource, withLinks)
 {
 }
 public Relationship(Object first, PropertyInfo second, RelationshipKind kind)
 {
     this._firstMember  = first;
     this._secondMember = second;
     this._kind         = kind;
 }