I am trying to associate the N:N relationship (Self referential) records in plugin. Example: Accounts to Accounts.
I am getting an exception of "Entity role must be specified for reflexive relationship".
Here is my code:
AssociateRequest associateRequest = new AssociateRequest();
associateRequest.Target = new EntityReference("iba_bc", BCId);
associateRequest.RelatedEntities = new EntityReferenceCollection();
foreach (var item in AssociatedBC)
associateRequest.RelatedEntities.Add(new EntityReference("iba_bc", new Guid(item.NewBCId.ToString())));
if (associateRequest.RelatedEntities.Count > 0)
associateRequest.Relationship = new Relationship("iba_bc_iba_bc");
associateRequest.Relationship.PrimaryEntityRole = EntityRole.Referenced;
var associateResponse = service.Execute(associateRequest);
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Yogesh Vijay Mulay
Your code looks ok - you have set the PrimaryEntityRole correctly.
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
Recheck following article -
Dynamics CRM MVP/ Technical Evangelist at
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?