Wie erstelle ich Daten aus der Entitätsbeziehung in CRM 2011 aus der Entitätsbeziehung?
-
25-10-2019 - |
Frage
Wie erstelle ich Daten aus der Entitätsbeziehung in CRM 2011 aus der Entitätsbeziehung?
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);
Fehlerexception: The 'Delete' method does not support entities of type 'entity1_entity2'.
Lösung
Um zwei Datensätze über eine n: n -Beziehung zu verknüpfen, müssen Sie die verwenden Assoziieren/Disassoziieren Anfrage oder die entsprechenden Methoden des Service -Proxy.
Dadurch wird der entsprechende Datensatz der Entity1_Entity2 Entity erstellt/löschen.
Andere Tipps
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
Hier ist ein Blog -Beitrag: http://charithrajapaksha.blogspot.com/2011/08/creating-many-t-many-records-in-crm.html
Zum Löschen versuchen Sie es unten
// 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);
In N: N -Beziehungen sollten die Aufzeichnungen zugeordnet und abgebaut werden. Sie können keine Datensätze in der N: n -Beziehung erstellen und löschen. Sie können assoziatere und disassociatrequest -Klassen verwenden oder assoziierte Nachrichten im Plugin -Registrierungswerkzeug verwenden.