I receive the following error when I trying to set up a new OData entry with a navigation property. The OData system I'm working on uses /ebecssvy_questionses(QUESTION_ID) as a navigation property. Here is the line that causes the error:
entity["ebecssvy_questionsid@odata.bind"] = "/ebecssvy_questionses(" + newId + ")";
Here is the error I receive when trying to POST the above entity using an XMLHttpRequest:
"error":{"code":"0x0","message":"An error occurred while validating input parameters: Microsoft.OData.ODataException: An ODataPrimitiveValue was instantiated with a value of type 'Microsoft.OData.ODataEntityReferenceLink'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types.\r\n at Microsoft.OData.ODataPrimitiveValue..ctor(Object value)\r\n at Microsoft.OData.ODataValueUtils.ToODataValue(Object objectToConvert)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.AttachODataAnnotations(IODataJsonLightReaderResourceState resourceState, String propertyName, ODataProperty property)\r\n at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.AddResourceProperty(IODataJsonLightReaderResourceState resourceState, String propertyName, Object propertyValue)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadEntryDataProperty(IODataJsonLightReaderResourceState resourceState, IEdmProperty edmProperty, String propertyTypeName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"}
I'm unsure what the issue is as I haven't worked with OData or CRM very extensively. The entity itself has all other properties cloned from a GET request of an existing record. I'm not sure how to fix this; Shouldn't entity.ebecssvy_questionsid@odata.bind be a primitive? Its value is a String, after all, and I would think a ODataEntityReferenceLink would be represented as a String. The ID is right, its the ID of the cloning target just incremented by one in the ID section that contains a random number. If more parts of the code or format of the OData are relevant, let me know, but both of those are quite large so I do not want to link them in their entirety.