You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code for writing an OData payload executes okay but produces an invalid output - the value for the Amount primitive property is a nested Customer resource/object:
varmodelBuilder=newODataConventionModelBuilder();modelBuilder.EntitySet<Order>("Orders");modelBuilder.EntitySet<Customer>("Customers");varmodel=modelBuilder.GetEdmModel();varorderEntityType=model.SchemaElements.First(d =>d.Name=="Order")asIEdmEntityType;varordersEntitySet=model.EntityContainer.FindEntitySet("Orders");varmessageWriterSettings=newODataMessageWriterSettings{EnableMessageStreamDisposal=false,Version=ODataVersion.V4,ODataUri=newODataUri{ServiceRoot=newUri("http://tempuri.org")}};vartempStream=newMemoryStream();IODataResponseMessageasyncResponseMessage=newInMemoryMessage{Stream=tempStream};awaitusing(varmessageWriter=newODataMessageWriter(asyncResponseMessage,messageWriterSettings,model)){varorderResource=newODataResource{TypeName=typeof(Order).FullName,Id=newUri("http://tempuri.org/Orders(1)"),Properties=newList<ODataProperty>{newODataProperty{Name="Id",Value=1}}};varcustomerResource=newODataResource{TypeName=typeof(Customer).FullName,Id=newUri("http://tempuri.org/Customers(1)"),Properties=newList<ODataProperty>{newODataProperty{Name="Id",Value=1},newODataProperty{Name="Name",Value="Sue"}}};varcustomerNestedResourceInfo=newODataNestedResourceInfo{Name="Amount",// Not a complex, complex collection or navigation propertyIsCollection=false,Url=newUri("http://tempuri.org/Orders(1)/Amount")};varresourceWriter=awaitmessageWriter.CreateODataResourceWriterAsync(ordersEntitySet,orderEntityType);awaitresourceWriter.WriteStartAsync(orderResource);awaitresourceWriter.WriteStartAsync(customerNestedResourceInfo);awaitresourceWriter.WriteStartAsync(customerResource);awaitresourceWriter.WriteEndAsync();awaitresourceWriter.WriteEndAsync();awaitresourceWriter.WriteEndAsync();tempStream.Position=0;varresult=awaitnewStreamReader(tempStream).ReadToEndAsync();// result: // {// "@odata.context":"http://tempuri.org/$metadata#Orders/$entity",// "@odata.id":"http://tempuri.org/Orders(1)",// "Id":1,// "Amount":{"@odata.id":"http://tempuri.org/Customers(1)","Id":1,"Name":"Sue"}// }}
Even worse, the library allows you to write the primitive property both with a primitive value as well as a nested resource resulting into a duplicate property, i.e., if you include the Amount property in the Properties collection as follows,
The library should validate the property assigned to the Name property of an ODataNestedResourceInfo is either a complex or complex collection or navigation property.
Actual result
The library does not validate the property assigned to the Name property of an ODataNestedResourceInfo is either a complex or complex collection or navigation property.
Additional detail
Here's the definition of the InMemoryMessage type:
ODL library allows you to write a nested resource as the value for a primitive property
Assemblies affected
Reproduce steps
Consider the following data models, where
Customer
is a navigation property:The following code for writing an OData payload executes okay but produces an invalid output - the value for the
Amount
primitive property is a nestedCustomer
resource/object:Even worse, the library allows you to write the primitive property both with a primitive value as well as a nested resource resulting into a duplicate property, i.e., if you include the
Amount
property in theProperties
collection as follows,Below is how the output payload will look like:
Expected result
The library should validate the property assigned to the
Name
property of anODataNestedResourceInfo
is either a complex or complex collection or navigation property.Actual result
The library does not validate the property assigned to the
Name
property of anODataNestedResourceInfo
is either a complex or complex collection or navigation property.Additional detail
Here's the definition of the
InMemoryMessage
type:The text was updated successfully, but these errors were encountered: