Thursday, 18 April 2013


Exception While associating a record of setting up relationships (N:N) between child and parent records same entity


Code Fix :
associateRequest.Relationship.PrimaryEntityRole = EntityRole.Referenced;


AssociateRequest associateRequest = new AssociateRequest();
            associateRequest.Target = new EntityReference("account", childAccount.AccountId.Value);
            associateRequest.RelatedEntities = new EntityReferenceCollection();
            associateRequest.RelatedEntities.Add(new EntityReference("account", parentAccount.AccountId.Value));
            associateRequest.Relationship = new Relationship("account_parent_account");
associateRequest.Relationship.PrimaryEntityRole = EntityRole.Referenced;
            var associateResponse = xrm.Execute(associateRequest);

No comments:

Post a Comment