简体   繁体   English

OData Web API,注册集合函数

[英]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. 我有一个Web API应用程序,其中已将Entityframework上下文连接为数据源,并且正在使用OData来“公开”我的数据。

However I need a custom function for my API called "WithInRange" that will take three parameters: * Longitude:float * Latitude:float * Range:float 但是,我需要为我的API定义一个自定义函数“ WithInRange”,它将使用三个参数:*经度:浮点*纬度:浮点*范围:浮点

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) 因此,基本上我想做的是使用以下网址〜/ 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. 然后,将检索具有该范围内所有MyObjects的数组。

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... 我认为我的主要问题是我没有真正了解如何针对我的ODataConventionModelBuilder-object注册该对象...

Any ideas? 有任何想法吗?

Br, Inx Br,Inx

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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