Dynamics 365多对多关系如何操作
我创建了一个 (多对多 )机会和自定义实体之间的关系。
CRM 会自动中断与称为“ 相交表”的内置表的关系。
在插件注册工具中,我想在这个特定的表上添加创建/更新/删除消息。但问题是那里不存在——甚至多对多系统关系也不存在。
那么该如何监听多对多关系呢?又如何进行绑定和解绑呢?
正确答案:
CRM 中关于多对多表/关系的范例是它们可用于 Association和 Disassociation请求但不适用于 Create , Update , 或 Delete要求。 (事实上,在交集表上没有真正的 Update - 新的关联只会被建立( Create => Associate )或被解除( Delete => Disassociate )。)
在 Association 上注册您的步骤信息。不幸的是,此消息无法过滤到特定实体,因此您必须过滤 全部 通过此插件在 CRM 中发出的关联请求。 IPluginExecutionContext在 InputParameters 中有一个名为“关系”的属性您可以使用属性包过滤掉要为其开发代码的关系。
1.通过OData如何查询多对多数据


2.通过OData如何添加多对多数据


3.多对多关系在后台如何查询
QueryExpression queryExpression = new QueryExpression("accountleads"); queryExpression.ColumnSet = new ColumnSet(true); queryExpression.Criteria.AddCondition("accountid", ConditionOperator.Equal, Guid.Parse("B0D5DF74-D430-EE11-8AE1-005056B69D9B")); var collection= AdminCrmConnect.OrgService.RetrieveMultiple(queryExpression);
4.多对多关系在后台如何添加和移除数据
//增加创建 AssociateEntitiesRequest associateEntitiesRequest = new AssociateEntitiesRequest() { RelationshipName = "accountleads" }; associateEntitiesRequest.Moniker1 = new EntityReference("account", new Guid("83fde645-0aba-eb11-b856-005056b6907f")); associateEntitiesRequest.Moniker2 = new EntityReference("lead", new Guid("11d2bb52-c4a7-eb11-b856-005056b6907f")); service.Execute(associateEntitiesRequest); //移除 DisassociateEntitiesRequest disassociateEntitiesRequest = new DisassociateEntitiesRequest() { RelationshipName = "accountleads" }; disassociateEntitiesRequest.Moniker1 = new EntityReference("account", new Guid("83fde645-0aba-eb11-b856-005056b6907f")); disassociateEntitiesRequest.Moniker2 = new EntityReference("lead", new Guid("11d2bb52-c4a7-eb11-b856-005056b6907f")); service.Execute(disassociateEntitiesRequest);
5.多对多关系如何注册插件实现业务控制

Relationship entityRelationship = (Relationship)context.InputParameters["Relationship"]; if (entityRelationship.SchemaName == "accountleads") { EntityReference targetEntity = (EntityReference)context.InputParameters["Target"]; EntityReferenceCollection relatedEntities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"]; foreach (EntityReference entityReference in relatedEntities) { if (entityReference.LogicalName == "account") { if (context.MessageName == "Associate") { throw new InvalidPluginExecutionException("非法操作1"); } if (context.MessageName == "Disassociate") { throw new InvalidPluginExecutionException("非法操作2"); } } } }
根据targetEntity.LogicalName和context.MessageName 为Associate或者Disassociate 来实现事件的监听。
浙公网安备 33010602011771号