Pregunta

¿Cómo crear y eliminar datos de la relación de entidad de muchos a muchos en CRM 2011?

Código:

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

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

¿Fue útil?

Solución

Para vincular dos registros a través de una relación n: n, debe usar el Asociado/Desasociar solicitud o los métodos correspondientes del proxy del servicio.

Esto creará/eliminará el registro correspondiente de la entidad Entity1_Entity2.

Otros consejos

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

Aquí hay una publicación de blog: http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html

Para eliminar su intento a continuación

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

En las relaciones N: n, los registros deben estar asociados y disociados. No puede crear y eliminar registros en la relación n: n. Puede usar las clases de AssociAterEquest, DisssociToterEquest o puede usar mensajes asociados y disociar en la herramienta de registro de complementos.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top