Quantcast
Channel: C# – Microsoft Dynamics CRM Blog
Viewing all articles
Browse latest Browse all 14

‘Entity role must be specified for reflexive relationship’ exception in Dynamics CRM 2011

$
0
0

This exception comes when you are trying to associate a record (account) to another record (account) having N:N relationship using C#. In my case account can have multiple payer accounts, got this exception when I was trying to associate payer account.

If you get this exception you need to mention relationship PrimaryEntityRole is EntityRole.Referenced or EntityRole.Referencing. Here is sample code


   public static void CreateAccountPayerRelationship(IOrganizationService service, Guid accountId, Guid payerAccountId)
        {
            Relationship relation = new Relationship("ls_account_account_payer");

            relation.PrimaryEntityRole = EntityRole.Referenced;

            EntityReference erPayerAccount = new EntityReference("account", payerAccountId);

            service.Associate("account", accountId, relation, new EntityReferenceCollection() { erPayerAccount });
        }


Viewing all articles
Browse latest Browse all 14

Trending Articles