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

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 });
        }

Advertisement

One thought on “‘Entity role must be specified for reflexive relationship’ exception in Dynamics CRM 2011

  1. Pingback: CRM 2011: Entity role must be specified for reflexive relationship | sliong

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s