OData Complex Type Containing an Entity Type Workaround
For OData Actions and POST I want to return a complex type which has a navigation property to an entity but that isn’t supported yet by Web API as Yi Ding replied to this question even though the v4 spec supports it:
As suggested I turned the complex type into an entity but the result I got back did not expand the entity pointed to by the navigation property. Adding $expand did nothing until I added [EnableQuery] to the method.
Having a POST annotated with [EnableQuery] and calling it with POST /odata/Foos?$expand=Bar looks a little odd but works and is allowed by the OData protocol.
The behavior was tested against Microsoft ASP.NET Web API 2.2 for OData v4.0 5.3.1, which is the latest released version available on NuGet.