/// <summary> /// Add AssociationAttribute if required for the specified property /// </summary> /// <param name="pd">The property</param> /// <param name="attributes">The list of attributes to append to</param> private void AddAssociationAttributes(PropertyDescriptor pd, ICollection <Attribute> attributes) { var entityType = (EntityType)EdmType; var navProperty = entityType.NavigationProperties.SingleOrDefault(n => n.Name == pd.Name); if (navProperty == null) { return; } var isManyToMany = navProperty.RelationshipType.RelationshipEndMembers[0].RelationshipMultiplicity == RelationshipMultiplicity.Many && navProperty.RelationshipType.RelationshipEndMembers[1].RelationshipMultiplicity == RelationshipMultiplicity.Many; if (isManyToMany) { return; } var assocAttrib = (AssociationAttribute)pd.Attributes[typeof(AssociationAttribute)]; if (assocAttrib != null) { return; } assocAttrib = TypeDescriptionContext.CreateAssociationAttribute(navProperty); attributes.Add(assocAttrib); }
/// <summary> /// Add AssociationAttribute if required for the specified property /// </summary> /// <param name="pd">The property</param> /// <param name="attributes">The list of attributes to append to</param> private void AddAssociationAttributes(PropertyDescriptor pd, List <Attribute> attributes) { EntityType entityType = (EntityType)EdmType; NavigationProperty navProperty = entityType.NavigationProperties.Where(n => n.Name == pd.Name).SingleOrDefault(); if (navProperty != null) { bool isManyToMany = navProperty.RelationshipType.RelationshipEndMembers[0].RelationshipMultiplicity == RelationshipMultiplicity.Many && navProperty.RelationshipType.RelationshipEndMembers[1].RelationshipMultiplicity == RelationshipMultiplicity.Many; if (!isManyToMany) { AssociationAttribute assocAttrib = (AssociationAttribute)pd.Attributes[typeof(System.ComponentModel.DataAnnotations.AssociationAttribute)]; if (assocAttrib == null) { assocAttrib = TypeDescriptionContext.CreateAssociationAttribute(navProperty); attributes.Add(assocAttrib); } } } }