简体   繁体   中英

OData Web API, Register a function for a collection

I have a Web API application where I have hooked up my Entityframework-context as the datasource and I'm using OData to "expose" my data.

However I need a custom function for my API called "WithInRange" that will take three parameters: * Longitude:float * Latitude:float * Range:float

public IQueryable<MyObject> WithInRange([FromODataUri] float longitude, float latitude, float range){
//DO STUFF
}

So basically what I would like to be able to do is to trigger the above "function/action" with the following url ~/odata/MyObjects/WithInRange(Longitude=11.12,Latitude=12.32,Range=1000)

And that would then retrive an array with all MyObjects thats with in that range.

However.. I cant really figure out how to do this.. Could someone please provide me with a brief working example? I think that my main problem is that I dont really get how to register this against my ODataConventionModelBuilder-object...

Any ideas?

Br, Inx

我认为该示例非常适合您,您可以按照示例逐步进行操作,任何问题都可以报告给odatafeedback@microsoft.com :)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM