Как создавать и удалять данные из отношения сущностей «многие ко многим» в CRM 2011?

Как создавать и удалять данные из отношения сущностей «многие ко многим» в crm 2011?

Код:

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);

Исключение ошибки: The 'Delete' method does not support entities of type 'entity1_entity2'.


person valch    schedule 10.01.2012    source источник


Ответы (4)


Чтобы связать две записи отношением N:N, необходимо использовать Ассоциировать/Disassociate или соответствующие методы сервисного прокси.

Это создаст/удалит соответствующую запись объекта entity1_entity2.

person ccellar    schedule 10.01.2012

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

Вот сообщение в блоге: http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html

person Tim Partridge    schedule 27.01.2012

Для удаления попробуйте ниже

        // Create an AssociateEntities request.
        //Namespace is Microsoft.Crm.Sdk.Messages
        DisassociateEntitiesRequest request = new DisassociateEntitiesRequest();

        // Set the ID of Moniker1 to the ID of the lead.
        request.Moniker1 = new EntityReference
        {
            Id = moniker1.Id,
            LogicalName = moniker1.Name
        };

        // Set the ID of Moniker2 to the ID of the contact.
        request.Moniker2 = new EntityReference
        {
            Id = moniker2.Id,
            LogicalName = moniker2.Name
        };

        // Set the relationship name to associate on.
        request.RelationshipName = strEntityRelationshipName;

        // Execute the request.
        service.Execute(request);
person chamara iresh    schedule 11.09.2014

В отношениях N:N записи должны быть связаны и разъединены. вы не можете создавать и удалять записи в отношении N:N. вы можете использовать классы AssociateRequest, DisassociateRequest или вы можете использовать сообщения Associate, Disassociate в инструменте регистрации плагинов.

person Community    schedule 12.07.2014