//</snippetWorkWithRelationships4> /// <summary> /// Deletes the relationships that was created for this sample. /// <param name="prompt">Indicates whether to prompt the user to delete /// the records created in this sample.</param> /// </summary> public void DeleteRequiredRecords(bool prompt) { bool deleteRecords = true; if (prompt) { Console.WriteLine("\nDo you want these entity relationships to be deleted? (y/n)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { //<snippetWorkWithRelationships5> DeleteRelationshipRequest deleteOneToManyRelationshipRequest = new DeleteRelationshipRequest { Name = "new_account_campaign" }; _serviceProxy.Execute(deleteOneToManyRelationshipRequest); DeleteRelationshipRequest deleteManyToManyRelationshipRequest = new DeleteRelationshipRequest { Name = "new_accounts_campaigns" }; _serviceProxy.Execute(deleteManyToManyRelationshipRequest); Console.WriteLine("Entity Relationships have been deleted."); //</snippetWorkWithRelationships5> } }
/// <summary> /// Deletes the custom entity record that was created for this sample. /// <param name="prompt">Indicates whether to prompt the user /// to delete the entity created in this sample.</param> /// </summary> public static void DeleteRequiredRecords(CrmServiceClient service, bool prompt) { bool deleteRecords = true; if (prompt) { Console.WriteLine("\nDo you want these entity records deleted? (y/n)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { var deleteOneToManyRelationshipRequest = new DeleteRelationshipRequest { Name = "new_account_contact" }; service.Execute(deleteOneToManyRelationshipRequest); var deleteManyToManyRelationshipRequest = new DeleteRelationshipRequest { Name = "new_accounts_contacts" }; service.Execute(deleteManyToManyRelationshipRequest); Console.WriteLine("Entity Relationships have been deleted."); } }
public bool DeleteRelationship(IOrganizationService service, XRMSpeedyRelationship relationship) { try { DeleteRelationshipRequest delete = new DeleteRelationshipRequest { Name = relationship.SchemaName }; service.Execute(delete); return(true); } catch (FaultException <OrganizationServiceFault> ) { throw; } }
public void DeleteRelationship(string relationshipName) { var request = new DeleteRelationshipRequest { Name = relationshipName }; Execute(request); if (AllRelationshipMetadata.Any(r => r.SchemaName == relationshipName)) { var relationship = GetRelationshipMetadata(relationshipName); AllRelationshipMetadata.Remove(relationship); } }
/// <summary> /// WARNING!! DELETES THE CUSTOM ENTITY /// </summary> /// <param name="schemaName"></param> public void DeleteEntity(string schemaName) { lock (LockObject) { var tempRequest1 = new RetrieveEntityRequest { LogicalName = schemaName, EntityFilters = EntityFilters.Relationships }; var response = (RetrieveEntityResponse) Execute(tempRequest1); foreach (var r in response.EntityMetadata.OneToManyRelationships) { if (r.IsCustomRelationship.HasValue && r.IsCustomRelationship.Value) { var tempRequest2 = new DeleteRelationshipRequest { Name = r.SchemaName }; Execute(tempRequest2); } } var request = new DeleteEntityRequest(); request.LogicalName = schemaName; Execute(request); if (GetAllEntityMetadata().Any(m => m.SchemaName == schemaName)) GetAllEntityMetadata().Remove(GetAllEntityMetadata().Single(m => m.SchemaName == schemaName)); if (_entityFieldMetadata.ContainsKey(schemaName)) _entityFieldMetadata.Remove(schemaName); } }