private void LoadSelectedEntityAttributes(string logicalName) { ResetEntityInformationPanel(); ((ListBox)chkdLstBxAllAttibutes).DataSource = Model.SelectedEntityAttributes; Dictionary <string, string> relatedEntitiesPluralNames = new Dictionary <string, string>(); WorkAsync(new WorkAsyncInfo { Message = "Getting entity attributes", Work = (worker, args) => { RetrieveEntityRequest entityRequest = new RetrieveEntityRequest(); entityRequest.LogicalName = logicalName; entityRequest.RetrieveAsIfPublished = true; entityRequest.EntityFilters = EntityFilters.All; var response = (RetrieveEntityResponse)Service.Execute(entityRequest); foreach (var mto1Relationship in response.EntityMetadata.ManyToOneRelationships) { RetrieveEntityRequest relatedEntityRequest = new RetrieveEntityRequest(); relatedEntityRequest.LogicalName = mto1Relationship.ReferencedEntity; relatedEntityRequest.EntityFilters = EntityFilters.Entity; RetrieveEntityResponse relatedEntityResponse = (RetrieveEntityResponse)Service.Execute(relatedEntityRequest); if (!relatedEntitiesPluralNames.ContainsKey(mto1Relationship.ReferencedEntity)) { relatedEntitiesPluralNames.Add(mto1Relationship.ReferencedEntity, relatedEntityResponse.EntityMetadata.LogicalCollectionName); } } // an attribute needs to be aware of all the collection names that it is related to. WebAPIAttributeItemModel.RelatedEntitiesPluralNames = relatedEntitiesPluralNames; args.Result = response.EntityMetadata.Attributes; }, PostWorkCallBack = (args) => { if (args.Error != null) { MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } var allAttributeMetaData = args.Result as AttributeMetadata[]; foreach (var attribute in allAttributeMetaData) { if (!MetadataValidator.IsValidAttribute(attribute)) { continue; } if (attribute.AttributeType == AttributeTypeCode.Customer) { WebAPIAttributeItemModel contactAttribute = new WebAPIAttributeItemModel(attribute, Model.SelectedEntityInfo, true, CustomerType.Contact); WebAPIAttributeItemModel accountAttribute = new WebAPIAttributeItemModel(attribute, Model.SelectedEntityInfo, true, CustomerType.Account); Model.AddAttribute(contactAttribute); Model.AddAttribute(accountAttribute); } else { WebAPIAttributeItemModel newAttribute = new WebAPIAttributeItemModel(attribute, Model.SelectedEntityInfo); Model.AddAttribute(newAttribute); } } ExecuteMethod(LoadEntityWebAPISettings, logicalName); } }); }