IOrganizationService.Disassociate(String, Guid, Relationship, EntityReferenceCollection) IOrganizationService.Disassociate(String, Guid, Relationship, EntityReferenceCollection) IOrganizationService.Disassociate(String, Guid, Relationship, EntityReferenceCollection) Method

Definition

Deletes a link between records.

public:
 void Disassociate(System::String ^ entityName, Guid entityId, Microsoft::Xrm::Sdk::Relationship ^ relationship, Microsoft::Xrm::Sdk::EntityReferenceCollection ^ relatedEntities);
[System.ServiceModel.FaultContract(typeof(Microsoft.Xrm.Sdk.OrganizationServiceFault))]
[System.ServiceModel.OperationContract]
public void Disassociate (string entityName, Guid entityId, Microsoft.Xrm.Sdk.Relationship relationship, Microsoft.Xrm.Sdk.EntityReferenceCollection relatedEntities);
abstract member Disassociate : string * Guid * Microsoft.Xrm.Sdk.Relationship * Microsoft.Xrm.Sdk.EntityReferenceCollection -> unit

Parameters

entityName
String String String

Type: String. The logical name of the entity that is specified in the entityId parameter.

entityId
Guid Guid Guid

Type: Guid. The ID of the record from which the related records are disassociated.

relationship
Relationship Relationship Relationship

Type: Relationship. The name of the relationship to be used to remove the link.

relatedEntities
EntityReferenceCollection EntityReferenceCollection EntityReferenceCollection

Type: EntityReferenceCollection. A collection of entity references (references to records) to be disassociated.

Examples

The following example demonstrates how to use the Disassociate(String, Guid, Relationship, EntityReferenceCollection) method to remove an association or link between records (early bound).


// Associate the accounts to the contact record.
   // Create a collection of the entities that will be
    // associated to the contact.
           
           var relatedEntities = new EntityReferenceCollection();
           relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account1Id));
           relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account2Id));
           relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account3Id));
           
       // Create an object that defines the relationship between the contact and account.
           var relationship = new Relationship("account_primary_contact");
           
       //Associate the contact with the 3 accounts.
           svc.Associate(Contact.EntityLogicalName, _contactId, relationship,
           relatedEntities);
           Console.WriteLine("The entities have been associated.");
           
       //Disassociate the records.
           svc.Disassociate(Contact.EntityLogicalName, _contactId, relationship,
           relatedEntities);

The following example demonstrates how to use the Disassociate(String, Guid, Relationship, EntityReferenceCollection) method to remove an association or link between records (late bound).


// The account ID would typically be passed in as an argument or determined by a query.
  // The contact ID would typically be passed in as an argument or determined by a query.
    // Associate the accounts to the contact record.
      //Create a collection of the entity ids that will be associated to the contact.
          
          var relatedEntities = new EntityReferenceCollection();
          relatedEntities.Add(new EntityReference("account", _account1Id));
          relatedEntities.Add(new EntityReference("account", _account2Id));
          relatedEntities.Add(new EntityReference("account", _account3Id));
      
      // Create an object that defines the relationship between the contact and account.
          var relationship = new Relationship("account_primary_contact");
          
      //Associate the contact with the 3 accounts.
          svc.Associate("contact", _contactId, relationship, relatedEntities);
          Console.WriteLine("The entities have been associated.");
      
      //Disassociate the records.
          svc.Disassociate("contact", _contactId, relationship, relatedEntities);

The following example demonstrates how to use the Disassociate(String, Guid, Relationship, EntityReferenceCollection) method to remove an association or link between records (early bound).

StrongTypes#AssociateDisassociate1 StrongTypesVB#AssociateDisassociate1

The following example demonstrates how to use the Disassociate(String, Guid, Relationship, EntityReferenceCollection) method to remove an association or link between records (late bound).

DynamicEntity#AssociateDisassociateDE1 DynamicEntityVB#AssociateDisassociateDE1

Remarks

Message Availability

This message works regardless whether the caller is connected to the server or offline.

Privileges and Access Rights

To perform this action, the caller must have privileges on the entity that is specified in the entityName parameter and access rights on the records that are specified in the entityId and relatedEntities parameters. For a list of the required privileges, see Delete message privileges.

Notes for Callers

This method removes multiple associations in one transaction between the record that is specified by the entityId parameter and each record in the relatedEntities parameter for the relationship that is specified in the relationship parameter.

For a one-to-many relationship, this method clears the ReferencingAttribute in the related record to the value of entityId.

For a many-to-many relationship, this method deletes a record in the intersect table for the relationship. The intersect table name is defined in the IntersectEntityName property for the relationship. You need this when you query for the records. However, you need the relationship name to set the Relationship property. This name is defined in the SchemaName property for the relationship.

For more information about the exceptions that can be thrown when this method is called, see Handle exceptions in your code.

Supported Entities

You can use this method to disassociate any records that participate in a relationship, including records for custom entities.

Applies to

See also