Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'.

like image 262
valch Avatar asked Dec 17 '22 05:12

valch


2 Answers

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.

like image 139
ccellar Avatar answered Dec 18 '22 19:12

ccellar


using Microsoft.Crm.Sdk.Messages;
...
// get the crm service
...
AssociateEntitiesRequest fooToBar = new AssociateEntitiesRequest
{
    Moniker1 = foo,                // foo is an entity reference
    Moniker2 = bar,                // bar is an entity reference
    RelationshipName = "foo_bar",  // name of the relationship
}

service.Execute(fooToBar)          // relates foo and bar

Here's a blog post: http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html

like image 29
Tim Partridge Avatar answered Dec 18 '22 20:12

Tim Partridge