[英]Organizing Master-Detail Controllers ASP.Net Web API
I am trying to determine the best way to implement the retrieval of detail records based upon the master's ID. 我正在尝试根据主人的ID确定实现详细记录检索的最佳方法。
Obviously you would set up API controllers for both master and detail. 显然,您将为master和detail设置API控制器。
Solutions I've considered: 我考虑过的解决方案:
I'd go with either #1 or #2. 我会选择#1或#2。
For #1, OData support enables not only the scenario you describe but offers a lot of additional functionality which might be desired in the future. 对于#1,OData支持不仅可以实现您描述的场景,还可以提供将来可能需要的许多附加功能。
For #2, I don't think it gets away from the point of Web API's. 对于#2,我认为它不会脱离Web API的角度。 Maybe a bit from a true RESTful service, but it's easy to implement and easy to understand.
也许有点来自真正的RESTful服务,但它易于实现且易于理解。
Option 2 will be fine. 选项2没问题。 Option 1 opens up a lot more risk depending on your scenario, and what you want to allow the user to get at.
选项1会根据您的方案以及您希望用户获得的内容开辟更多风险。
It's not really "against convention" to add custom methods to an ApiController. 向ApiController添加自定义方法并不是“违反惯例”。 You can do that however you like.
你可以随心所欲地做到这一点。 It would only be "against convention" if you did so and used the wrong HTTP methods (ie a GET when you're deleting something in your custom method).
如果您这样做并且使用了错误的HTTP方法(即在您的自定义方法中删除某些内容时为GET),它将只是“违反惯例”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.