本文介绍了在EntitySetController附加GetXYZ方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能在我的EntitySetController派生控制器类附加GetXYZ方法。例如:

  [HTTPGET]
 [可查询]
        公共字符串GetAirportsWithinRadius(INT airportId,诠释半径)
        {            VAR resultAirports = GetAirportsWithinRadius2(airportId,半径);            返回resultAirports;
        }

这是我对配置:

  ActionConfiguration getAirportsWithinRadius = modelBuilder.Entity<机场方式>()Collection.Action(GetAirportsWithinRadius);
        getAirportsWithinRadius.Parameter&所述; INT&GT(airportId);
        getAirportsWithinRadius.Parameter< INT>(半径);
        getAirportsWithinRadius.ReturnsCollectionFromEntitySet<机场及GT;(机场);

我想这个动作是可组合就像默认获取可查询的动作,但是这将是支持所有ODATA参数,但另外一个airportId和半径的替代品。这将首​​先通过过滤半径搜索机场(这个我知道怎么做 - 这是无关的问题),然后返回可查询,以便它可以通过ODATA PARAMS进一步筛选

一切我读到说这将是一个ODATA行动,因此必须有一个职位,但得到的是同样的动作,这是一个GET,所以为什么不让扩展干将与其他参数?我缺少的东西吗?我如何做到我想要得到做了什么?

我想从Ajax客户端这样调用这个:
GET / ODATA /机场$ inlinecount =所有页和放大器; $顶部= 25安培; airportId = 2112&安培;半径= 50

而不是一个普通ODATA GET:
GET / ODATA /机场$ inlinecount =所有页和放大器; $顶部= 25

感谢

编辑:
我现在明白了,这是一个ODATA功能,它正在考虑为将来的功能。让我们忘记秒这个ODATA意义。它本质上是一个HTTPGET的WebAPI返回一个可查询的,对不对?所以,只要我不关心这个功能的广告元数据,如何才能确保它是一个HTTPGET可达形成ODataController内部路由的角度?该ODataController需要MapODataRoute和我可以另加使用额外的MapHttpRoutes非ODATA路线?
我问这个,因为在我看来,我应该是可以的,但我所有的尝试都失败了(试图通过小提琴手打HTTPGET)。我能找到与更多的非ODATA GET的延伸ODataController没有例子。有人可以帮助我理解是否和如何这可以用这个例子来完成:

  [可查询]
        公众的IQueryable<机场及GT;得到()
        {
            返回db.Airports;
        }
    [HTTPGET]
     [可查询]
            公共字符串GetAirportsWithinRadius(INT airportId,诠释半径)
            {                VAR resultAirports = GetAirportsWithinRadius2(airportId,半径);                返回resultAirports;
            }


解决方案

您正在寻找的OData功能,这些功能目前还不支持开箱即用。我们在这里的一个问题。您最多可以-投票吧。

的http://aspnetwebstack.$c$cplex.com/workitem/881

I want to be able to have additional GetXYZ methods in my EntitySetController derived controller class. For example:

[HttpGet]
 [Queryable]
        public string GetAirportsWithinRadius(int airportId, int radius)
        {

            var resultAirports = GetAirportsWithinRadius2(airportId, radius);

            return resultAirports;            
        }

This is what I have for config:

ActionConfiguration getAirportsWithinRadius =  modelBuilder.Entity<Airport>().Collection.Action("GetAirportsWithinRadius");
        getAirportsWithinRadius.Parameter<int>("airportId");
        getAirportsWithinRadius.Parameter<int>("radius");
        getAirportsWithinRadius.ReturnsCollectionFromEntitySet<Airport>("Airports");

I want this action to be composable just like the default Get Queryable action, but this would be an alternative that supports all odata parameters but additionally an airportId and radius. This would first filter airports by a radius search (this I know how to do - it's irrelevant to the question) and then return the Queryable so that it can be further filtered by odata params.

Everything I read says this would be an odata action and therefore must be a POST, but Get is also an action and that is a GET, so why not allow extended getters with additional parameters? Am I missing something? How do I accomplish what I want to get done?

I would call this from an ajax client as such:GET /odata/Airports?$inlinecount=allpages&$top=25&airportId=2112&radius=50

as opposed to a regular odata GET:GET /odata/Airports?$inlinecount=allpages&$top=25

Thanks

EDIT:I understand now that this is an odata "function" and it is under consideration as a future feature. Let's forget for second the odata meaning of this. It is essentially a WebApi HttpGet that returns a Queryable, right? So, as long as I don't care about the metadata advertising of this "function", how can I make sure that it is a reachable HttpGet form a route perspective inside of an ODataController? The ODataController needs the MapODataRoute and can I additionally add non odata routes using additional MapHttpRoutes?I ask this because it seems to me that I should be able to, but all my tries have failed (trying to hit the HttpGet through fiddler). I can find no examples on extending an ODataController with additional non-odata GETs. Can someone help me understand if and how this can be done with the example?:

[Queryable]
        public IQueryable<Airport> Get()
        {
            return db.Airports;
        }
    [HttpGet]
     [Queryable]
            public string GetAirportsWithinRadius(int airportId, int radius)
            {

                var resultAirports = GetAirportsWithinRadius2(airportId, radius);

                return resultAirports;            
            }
解决方案

You are looking for OData Functions, which is not yet supported out of the box. We have an issue over here. You can up-vote it.

http://aspnetwebstack.codeplex.com/workitem/881

这篇关于在EntitySetController附加GetXYZ方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:02