I have a relationship between Opportunities and my custom Contract entity in Dynamics 2016 on premise. I am trying to retrieve all of the related contracts from a particular opportunity in a C# plugin. When I try to retrieve the relationships, I receive the error:
No system many-to-many relationship exists between opportunity and ccseq_contract. If attempting to link through a custom many-to-many relationship ensure that you provide the from and to attributes.
It appears that the relationship does exist based on this screenshot:
Here's my Query Expression:
EntityCollection contracts = service.RetrieveMultiple(new QueryExpression()
{
EntityName = Opportunity.LogicalName,
ColumnSet = new ColumnSet(new String[]
{
Opportunity.Properties.OpportunityId
}),
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = Opportunity.LogicalName,
LinkToEntityName = Contract.LogicalName,
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = Opportunity.Properties.OpportunityId,
Operator = ConditionOperator.Equal,
Values = {wonOpportunity.Id}
}
}
}
}
}
});
Why am I receiving this error and how can I resolve the error?