我需要创建/定义引线和自定义实体之间以及联系人和自定义实体之间的多到多关系。我似乎找不到任何代码示例来说明我想要做什么。
这需要同时适用于CRM 4和CRM 5。
做两个N:1关系而不是N:N关系有什么缺点吗?
发布于 2011-06-01 18:35:15
您可以通过UI通过实体N:N关系来进行N:N关系。与中间实体进行2N:1关系比执行单个N:N更有好处,例如您可以存储关系属性(关系的角色),还可以通过双N:1关系链接工作流。
编辑:
要通过代码创建N:N关系,您可以参考下面摘录的CRM2011SDK帮助页面“创建和检索实体关系”。您可以通过4.0中的元数据服务做类似的事情-
创建N:N实体关系
下面的示例使用EligibleCreateManyToManyRelationship方法验证帐户和活动实体可以参与N:N实体关系,然后使用CreateManyToManyRequest创建实体关系。
bool accountEligibleParticipate =
EligibleCreateManyToManyRelationship("account");
bool campaignEligibleParticipate =
EligibleCreateManyToManyRelationship("campaign");
if (accountEligibleParticipate && campaignEligibleParticipate)
{
CreateManyToManyRequest createManyToManyRelationshipRequest =
new CreateManyToManyRequest
{
IntersectEntitySchemaName = "new_accounts_campaigns",
ManyToManyRelationship = new ManyToManyRelationshipMetadata
{
SchemaName = "new_accounts_campaigns",
Entity1LogicalName = "account",
Entity1AssociatedMenuConfiguration =
new AssociatedMenuConfiguration
{
Behavior = AssociatedMenuBehavior.UseLabel,
Group = AssociatedMenuGroup.Details,
Label = new Label("Account", 1033),
Order = 10000
},
Entity2LogicalName = "campaign",
Entity2AssociatedMenuConfiguration =
new AssociatedMenuConfiguration
{
Behavior = AssociatedMenuBehavior.UseLabel,
Group = AssociatedMenuGroup.Details,
Label = new Label("Campaign", 1033),
Order = 10000
}
}
};
CreateManyToManyResponse createManytoManyRelationshipResponse =
(CreateManyToManyResponse)_serviceProxy.Execute(
createManyToManyRelationshipRequest);
_manyToManyRelationshipId =
createManytoManyRelationshipResponse.ManyToManyRelationshipId;
_manyToManyRelationshipName =
createManyToManyRelationshipRequest.ManyToManyRelationship.SchemaName;
Console.WriteLine(
"The many-to-many relationship has been created between {0} and {1}.",
"account", "campaign");
}EligibleCreateManyToManyRelationship
下面的示例创建一个EligibleCreateManyToManyRelationship方法,该方法使用CanManyToManyRequest验证实体是否可以参与N:N实体关系。
/// <summary>
/// Determines whether the entity can participate in a many-to-many relationship.
/// </summary>
/// <param name="entity">Entity</param>
/// <returns></returns>
public bool EligibleCreateManyToManyRelationship(string entity)
{
CanManyToManyRequest canManyToManyRequest = new CanManyToManyRequest
{
EntityName = entity
};
CanManyToManyResponse canManyToManyResponse =
(CanManyToManyResponse)_serviceProxy.Execute(canManyToManyRequest);
if (!canManyToManyResponse.CanManyToMany)
{
Console.WriteLine(
"Entity {0} can't participate in a many-to-many relationship.",
entity);
}
return canManyToManyResponse.CanManyToMany;
}https://stackoverflow.com/questions/6202329
复制相似问题