简体   繁体   English

ODATA方法设计模式

[英]ODATA method design pattern

I'm new to OData although familiar with WebAPI routing... 我是OData的新手,尽管熟悉WebAPI路由...

I have two collections USERS and TEAMS with their controllers constructed from EF6. 我有两个集合USERS和TEAMS,它们的控制器是由EF6构建的。 From both I can return all the users or a single 我可以从这两者返回所有用户或一个

USERS
http://localhost:50798/odata/members
http://localhost:50798/odata/members(1)

TEAMS
http://localhost:50798/odata/teams
http://localhost:50798/odata/teams(1)

I need to return the team on a specific member ID. 我需要返回特定成员ID的团队。 Through OData the method name is ignored and what I instinctively want to do is put a method in the teams controller, say "GetTeamFromMember", it then join from the users collection to the teams collection and return the single team. 通过OData,方法名称将被忽略,而我本能地想要做的就是将一个方法放置在teams控制器中,例如“ GetTeamFromMember”,然后将其从用户集合加入到teams集合中,并返回单个团队。

What is the best way to do this? 做这个的最好方式是什么?

You can add specific methods called functions with OData but what you are doing here is perfect for OData navigation properties. 您可以使用OData添加称为函数的特定方法,但是您在此处所做的操作非常适合OData导航属性。 You can navigate relationships from entities. 您可以从实体导航关系。 For example, the URL for what you are trying to do here could then be: 例如,您在此处尝试执行的操作的URL可能是:

http://localhost:50798/odata/members(1)/team

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

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