如何在CRM 2011中从实体关系中创建和删除数据?
-
25-10-2019 - |
题
如何在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);
FARDEXCEPTION: The 'Delete' method does not support entities of type 'entity1_entity2'.
其他提示
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
对于删除,您可以在下面尝试
// 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);
在n:n关系中,记录应关联和分离。您无法在n:n关系中创建和删除记录。您可以使用AssociaTerequest,DisassociaTerEquest类,也可以在插件注册工具中使用合作,拆卸消息。
不隶属于 StackOverflow