首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CRM 4和C# 5中创建多到多的关系

在CRM 4和C# 5中创建多到多的关系
EN

Stack Overflow用户
提问于 2011-06-01 13:55:14
回答 1查看 3.6K关注 0票数 2

我需要创建/定义引线和自定义实体之间以及联系人和自定义实体之间的多到多关系。我似乎找不到任何代码示例来说明我想要做什么。

这需要同时适用于CRM 4和CRM 5。

做两个N:1关系而不是N:N关系有什么缺点吗?

EN

回答 1

Stack Overflow用户

发布于 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创建实体关系。

代码语言:javascript
复制
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实体关系。

代码语言:javascript
复制
/// <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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6202329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档