web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error Associating N:N Relationship

(0) ShareShare
ReportReport
Posted on by 20

We are running into an error associating N:N entities via the Web API. Most of the related forum posts we have came across suggest inverting the entities, but we are getting an error regardless of which side we treat as the parent. To rule out a one-off error with this N:N relationship, we've also tried creating a new N:N relationship between the same two entities, but get the same corresponding errors. Below are sample Web API calls and returned errors, as well as a screenshot of the relationship. Any help would be appreciated. 


4338.relationship.jpg

Request 1:

POST https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)/str_strsalesorder_systemuser/$ref HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0

{"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)"}

Response 1:

HTTP/1.1 500 Internal Server Error
OData-Version: 4.0

{
  "error":{
    "code":"","message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","innererror":{
      "message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","type":"Microsoft.Crm.CrmException","stacktrace":"   at Microsoft.Crm.CrmException.Assert(Boolean condition, String message)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetNavigationPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, IEdmProperty edmProperty, EntityRelationship entityRelationship, Object propertyValue, Nullable`1 role)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n   at Microsoft.Crm.Extensibility.OData.EdmTypeConverter.ConvertToCrmEntity(EdmEntityObject edmEntity, EntityReference entityReference)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceProperty(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String propertyName, Object edmPropertyValue)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

-----------

Request 2:

POST https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)/str_strsalesorder_systemuser/$ref HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0

{"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)"}


Response 2:

HTTP/1.1 400 Bad Request
OData-Version: 4.0

{
  "error":{
    "code":"","message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","innererror":{
      "message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi, I'm encountering the same issue. Either option generates an error like Josh describes. Has anyone found a solution?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans