如何在CRM 2011中创建和删除多对多实体关系中的数据?

val*_*lch 4 c# web-services crm dynamics-crm dynamics-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);
Run Code Online (Sandbox Code Playgroud)

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

cce*_*lar 5

为了通过N:N关系链接两个记录,您必须使用Associate/Disassociate请求或服务代理的相应方法.

这将创建/删除entity1_entity2实体的相应记录.


Tim*_*dge 5

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
Run Code Online (Sandbox Code Playgroud)

这是一篇博客文章:http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html