Returning a ComplexType with a NavigationProperty from a function
I'm trying to write an OData function which returns a ComplexType containing two lists of entities:
<Function Name="foo" IsBound="true">
<Parameter Name="bindingParameter" Type="root" />
<ReturnType Type="bar" />
</Function>
<ComplexType Name="bar">
<NavigationProperty Name="list_one" Type="Collection(baz)" />
<NavigationProperty Name="list_two" Type="Collection(baz)" />
</ComplexType>
<EntityType Name="baz">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="Edm.String" Nullable="false" />
<Property Name="displayName" Type="Edm.String" Nullable="false" />
<Property Name="createdDateTime" Type="Edm.DateTimeOffset" />
</EntityType>
However, this function does not return any data! Instead, all I get back is the @odata.context key/value, with no other information.
{
"@odata.context": "http://localhost:26693/root/$metadata#foo"
}
Assemblies affected
Microsoft.OData.OData version 7.5.14 (and probably others, this is the one I'm using now)
Reproduce steps
- Call the function with
GET http://localhost:26693/root/foo() - Observe that there is no response data
- Open new OData bug
Expected result
I would expect both of the lists to appear, even if they have no data:
{
"list_one": [],
"list_two": [],
}
or, if data was present, I would expect it to appear in the list:
{
"list_one": [
{
"id": "1",
"displayName": "Alice",
"createdDateTime": null,
}],
"list_two": [],
}
Actual result
In actuality, neither list appears -- not even when I pass ?$expand=list_one,list_two.
Additional details
@xuzhg was able to help me out with a workaround, by providing a custom serializer. As such, I am not actually blocked by this bug.
Also, I should mention that this is affecting a feature which is not yet released -- as such, I have replaced the names (and thus this may not quite work as written). For a more accurate details, please see the internal stackoverflow question.
As stated in the StackOverflow question, support for returning a NavigationProperty from a function that returns a complex type is currently not in place. A workaround is possible for now but there's a need to address the feature gap.