c# - OData 4 AspNet: GET by parameter not working -


i'm in process of converting web service use odata. i've created odatacontroller implementation below:

public class personcontroller : odatacontroller {      public personcontroller()     {      }      public ihttpactionresult get()     {         return ok(new person());     }      public ihttpactionresult get([fromodatauri] int key)     {         return ok(new person());     }      protected override void dispose(bool disposing)     {     } } 

and registered model so:

var builder = new odataconventionmodelbuilder(); builder.entityset<person>("person");  config.maphttpattributeroutes();  config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } );  config.mapodataserviceroute( routename: "odata", routeprefix: "odata", model: builder.getedmmodel()); 

the web app deploys without problems, , first function works when call:

http://localhost:9200/odata/customer  -> {   "@odata.context":"http://localhost:9200/odata/$metadata#person/$entity","name":"john" } 

however, calling http://localhost:9200/odata/customer(1) fails, trace on server log shows route not found:

iisexpress.exe information: 0 : response, status=404 (notfound), method=get, url=http://localhost:9200/odata/person(1), message='content-type='application/xml; charset=utf-8', content-length=unknown' 

i've tried different attribute permutations using odatarouteprefix, odataroute, enablequery on method, , far nothing seems help. tutorials have seen should work, i'm stuck wondering how i'm supposed working. have ideas?

i managed solve own problem.

the problem was, key defined within entity of type string. meant key extracted fromodatauri had of type string!

in example, problem fixed changing key string type, or changing person key int type.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -