private void AddOneToMany() { OneToManyRelationshipMetadata relationship = new OneToManyRelationshipMetadata { ReferencedEntity = ToEntity, ReferencingEntity = Entity, SchemaName = Name }; if (_context != null) { _context.SetParametersOnRelationship(relationship); } LookupAttributeMetadata lookup = new LookupAttributeMetadata { SchemaName = AttributeName, DisplayName = new Label(AttributeDisplayName, CrmContext.Language), Description = new Label(AttributeDescription ?? string.Empty, CrmContext.Language) }; AttributeRequiredLevel requiredLevel = AttributeRequiredLevel.ApplicationRequired; if (AttributeRequired == CrmRequiredLevel.Required) { requiredLevel = AttributeRequiredLevel.ApplicationRequired; } if (AttributeRequired == CrmRequiredLevel.Recommended) { requiredLevel = AttributeRequiredLevel.Recommended; } if (AttributeRequired == CrmRequiredLevel.Optional) { requiredLevel = AttributeRequiredLevel.None; } lookup.RequiredLevel = new AttributeRequiredLevelManagedProperty(requiredLevel); Guid result = _repository.AddRelationship(relationship, lookup); if (PassThru) { WriteObject(_repository.GetRelationship(result)); } }