asp.net mvc - .net MVC Odata endpoint works on POST, but 404s on GET -
my question should have simple answer, after hours of experimentation , googling, have nothing i'm here.
i working .net mvc 5 odata 2.0. trying create new odata endpoint works on get. i've created few endpoints work post, can't seem 1 works get.
relevant code
webapiconfig.cs
odataconventionmodelbuilder builder = new odataconventionmodelbuilder(); builder.entityset<review>("reviews"); builder.entityset<strategy>("strategies"); actionconfiguration reviewsinstrategy = builder.entity<strategy>().action("reviewsinstrategy"); reviewsinstrategy.returnscollectionfromentityset<review>("reviews"); config.routes.mapodataserviceroute("odata", "odata", builder.getedmmodel());
strategiescontroller.cs
[enablequery] public iqueryable<review> reviewsinstrategy([fromodatauri] guid key){ strategy strategy = db.strategies.find(key); return strategy.reviews }
now go fiddler , try
[myurl]/odata/strategies(guid'[myguid]')/reviewsinstrategy
i 404 result. when change fiddler post (no other change - don't add accept headers or content types or anything) works fine.
how make work get?
you need add get-function controller:
[enablequery] public singleresult<strategies> get([fromodatauri] guid key) { iqueryable<strategies> result = db.strategies.where(p => p.id == key); return singleresult.create(result); }
that way can use request on strategies-resource. if still want use custom action must add parameter config:
actionconfiguration reviewsinstrategy = builder.entity<strategy>().action("reviewsinstrategy").returns<review>().parameter<guid>("key"); [httpget] [odataroute("reviewsinstrategy(key={key})")] public ihttpactionresult<review> reviewsinstrategy([fromodatauri] guid key){ strategy strategy = db.strategies.find(key); return ok(strategy.reviews); }
not sure if works complex type guid
. maybe need change string , parse inside function. here msdn article this.
Comments
Post a Comment