We have a project based on the DynamicEdmModelCreation project from ODataSamples-master odata examples.
We have set a Routing Convention that handle all request to this specific controller:
[HttpGet]
[EnableQuery]
public EdmEntityObjectCollection Get()
{
...
}
[EnableQuery]
public IEdmEntityObject Get(string key)
{
...
}
We try for example
/odata/Hotels -> OK!
/odata/Hotels(1) -> Ok!
/odata/Hotels(1)/Room -> Response:
No routing convention was found to select an action for the OData path with template '~/entityset/key/navigation'.
Debuging we see that the route convention handle well the request and redirect it to our controller but no method is executed. The Routing Convention is:
public class MatchRoutingConventionService : IODataRoutingConvention
{
public string SelectAction(
ODataPath odataPath,
HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
return null;
}
public string SelectController(ODataPath odataPath, HttpRequestMessage request)
{
return (odataPath.Segments.FirstOrDefault() is EntitySetPathSegment) ? "HamdleAll" : null;
}
}
We think the problem may be in WebApi chossing the correct method that will handle the request because since we are using the generic signature IEdmEntityObject Get(string key).
In your controller, there're only two methods named Get(), Get(string key)
. The result is:
/odata/Hotels
is ok because the request can route to Get()
method by convention.
/odata/Hotels(1)
is ok because the request can route to Get(string key)
by convention.
However, you doesn't create other methods to response other requests, such as for the request example:
/odata/Hotels(1)/Room
Owing that there's no methods responding to ~/entityset/key/navigation
, Web API OData can't find a method in your controller, so it throws the above error message.
I create a simple method in https://github.com/xuzhg/ODataSamples/commit/289658ab5d7bb50c6270400946990c27809d44bc
Besides, I also create the general navigation property access route in SelectAction
the MatchAllRoutingConvention
. See the commit:
https://github.com/xuzhg/ODataSamples/commit/200c4abd346f14ad258df2b36e8687f8ab7d85e7
You can modify it to meet your requirement. Hope it can help you.
Thanks.
Sam