c# - Handle Odata /entityset/key/navigation -
we have project based on dynamicedmmodelcreation project odatasamples-master odata examples.
we have set routing convention handle request specific controller:
[httpget] [enablequery] public edmentityobjectcollection get() { ... } [enablequery] public iedmentityobject get(string key) { ... }
we try example
/odata/hotels -> ok!
/odata/hotels(1) -> ok!
/odata/hotels(1)/room -> response:
no routing convention found select action odata path template '~/entityset/key/navigation'.
debuging see route convention handle request , redirect our controller no method executed. 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() entitysetpathsegment) ? "hamdleall" : null; } }
we think problem may in webapi chossing correct method handle request because since using generic signature iedmentityobject get(string key).
in controller, there're 2 methods named get(), get(string key)
. result is:
/odata/hotels
ok because request can routeget()
method convention./odata/hotels(1)
ok because request can routeget(string key)
convention.
however, doesn't create other methods response other requests, such request example:
/odata/hotels(1)/room
owing there's no methods responding ~/entityset/key/navigation
, web api odata can't find method in controller, throws above error message.
my try:
i create simple method in https://github.com/xuzhg/odatasamples/commit/289658ab5d7bb50c6270400946990c27809d44bc
besides, create general navigation property access route in
selectaction
matchallroutingconvention
. see commit: https://github.com/xuzhg/odatasamples/commit/200c4abd346f14ad258df2b36e8687f8ab7d85e7
you can modify meet requirement. hope can you.
thanks.
sam
Comments
Post a Comment