How to create and delete data from entity relationship many-to-many in CRM 2011?

valch picture valch · Jan 10, 2012 · Viewed 9.8k times · Source

How to create and delete data from entity relationship many-to-many in crm 2011?

Code:

QueryExpression qry = new QueryExpression();
qry.EntityName = "entity1_entity2";
qry.ColumnSet = new ColumnSet(true);

var re = crmservice.RetrieveMultiple(qry).Entities;


crmservice.Delete("entity1_entity2", re[0].Id);

FaultException: The 'Delete' method does not support entities of type 'entity1_entity2'.

Answer

ccellar picture ccellar · Jan 10, 2012

In order to link two records via a N:N relationship, you have to use the Associate/Disassociate request or the corresponding methods of the service proxy.

This will create/delete the corresponding record of the entity1_entity2 entity.