private static AssociationEndMember InitializeAssociationEndMember( AssociationType associationType, IRelationshipEnd end, EntityType endMemberType) { EdmMember edmMember; AssociationEndMember associationEndMember; if (!associationType.Members.TryGetValue(end.Name, false, out edmMember)) { associationEndMember = new AssociationEndMember(end.Name, endMemberType.GetReferenceType(), end.Multiplicity.Value); associationType.AddKeyMember((EdmMember)associationEndMember); } else { associationEndMember = (AssociationEndMember)edmMember; } RelationshipEnd relationshipEnd = end as RelationshipEnd; if (relationshipEnd != null && relationshipEnd.Documentation != null) { associationEndMember.Documentation = Converter.ConvertToDocumentation(relationshipEnd.Documentation); } return(associationEndMember); }
public static string GetRelationLabel(RelationshipEnd source, RelationshipEnd target) { string label = GetRelationLabel((int)source | (int)target); if (label == null) { throw new InvalidOperationException(string.Format("Relationship between {0} and {1} are invalid", source.ToString(), target.ToString())); } return(label); }
public Relationship(BaseNode source, BaseNode target, string label, DateTimeOffset creationDate) { Source = source; Target = target; Label = label; CreationDate = creationDate; _sourceType = RelationshipEnd.USER; if (Source is User) { _sourceType = RelationshipEnd.USER; } else if (Source is Product) { _sourceType = RelationshipEnd.ITEM; } else if (Source is Interest) { _sourceType = RelationshipEnd.INTEREST; } else if (Source is Tag) { _sourceType = RelationshipEnd.TAG; } _targetType = RelationshipEnd.USER; if (Target is User) { _targetType = RelationshipEnd.USER; } else if (Target is Product) { _targetType = RelationshipEnd.ITEM; } else if (Target is Interest) { _targetType = RelationshipEnd.INTEREST; } else if (Target is Tag) { _targetType = RelationshipEnd.TAG; } }
override public bool VisitRelationship(QueryBuilderMappingParser.RelationshipContext context) { if (Pass == 2) { // RelationshipCardinality deveria fazer parte de RelationshipConnection Relationship relationship = new Relationship(context.name.Text); foreach (QueryBuilderMappingParser.AttributeContext ac in context.attribute()) { relationship.AddAttribute(ac.name.Text, ac.type.Text, ac.multivalued != null, ac.primarykey != null); } foreach (var end in context.relationshipEnd()) { RelationshipEnd rend = new RelationshipEnd(); try { var target = EntityRelationshipModel.FindByName(end.name.Text); if (target.GetType() != typeof(Entity)) { Errors.Add($"Error 003: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' is not an Entity!"); } else { rend.TargetEntity = (Entity)target; relationship.AddRelationshipEnd(rend); } } catch (Exception) { Errors.Add($"Error 004: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' not found!"); } } EntityRelationshipModel.Elements.Add(relationship); } return(true); }
internal static IEnumerable<Type> GetAllowedNodeTypes(Type relationshipType, RelationshipEnd end) { Type interfaceType; switch (end) { case RelationshipEnd.SourceNode: interfaceType = typeof (IRelationshipAllowingSourceNode<>); break; case RelationshipEnd.TargetNode: interfaceType = typeof (IRelationshipAllowingTargetNode<>); break; default: throw new NotSupportedException(string.Format( "The specified relationship end is not supported: {0}", end)); } return relationshipType .GetInterfaces() .Where(i => i.GetGenericTypeDefinition() == interfaceType) .Select(i => i.GetGenericArguments()[0]) .ToArray(); }
internal static IEnumerable <Type> GetAllowedNodeTypes(Type relationshipType, RelationshipEnd end) { Type interfaceType; switch (end) { case RelationshipEnd.SourceNode: interfaceType = typeof(IRelationshipAllowingSourceNode <>); break; case RelationshipEnd.TargetNode: interfaceType = typeof(IRelationshipAllowingTargetNode <>); break; default: throw new NotSupportedException(string.Format( "The specified relationship end is not supported: {0}", end)); } return(relationshipType .GetInterfaces() .Where(i => i.GetGenericTypeDefinition() == interfaceType) .Select(i => i.GetGenericArguments()[0]) .ToArray()); }