在 MVC 应用程序上公开 OData
我想为我的用户提供丰富的查询功能,以便他们可以动态添加Where 子句、更改排序顺序和分组。 oData 似乎是最适合这项工作的技术,但我不知道如何在 MVC 应用程序中正确实现它。
1) 如何使用 MVC 架构连接支持 oData 的功能丰富的客户端?
2) 我必须在我的存储库上公开 IQueryable 吗?
3) 谁能解释一下在 MVC 中使用 2 个连接表时如何创建、更新或删除? (在服务层?)
I want to offer my users a rich query functionality so they can dynamically add Where clauses, change sort orders and groupings. oData seems to be the best technology for the job, but I don't know how to implement it correctly in a MVC application.
1) How can I connect a feature rich client that supports oData with a MVC architecture?
2) Must I expose IQueryable on my repository?
3) Can anyone explain how to Create, Update, or Delete when using 2 joined tables in MVC? (in the service layer?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
开始学习 OData 的好地方是:
http://msdn.microsoft.com/en-us/data/odata.aspx
一般而言,如果需要,则应使用 OData 和 Web 服务,因为 1) 出于安全或性能原因需要将物理层分开,或者 2) 多个应用程序或消费者需要使用相同的 API。当然还有其他原因,但通常如果您必须询问 OData 是否有意义,您就没有这些要求。 ;)
A good place to start learning about OData is here:
http://msdn.microsoft.com/en-us/data/odata.aspx
In General OData and Web Services should be used if they are required because 1) You physical tiers need to be separated for security or performance reasons or 2) Multiple applications or consumers need to use the same API. There are of course other reasons but generally if you have to ask if OData makes sense you don't have those requirements. ;)
我正在 MVC 中编写 Restfull API 并找到了 ODATA。 MS 的出色实施。
http://www.asp.net/web -api/overview/odata-support-in-aspnet-web-api
是您可以很好地开始使用 odata 的地方。
我查看了此页面
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/getting- start-with-odata-in-web-api/create-a-read-only-odata-endpoint
并立即启动并运行。
希望这有帮助。与设计和消费一起工作真是太好了。
www.odata.org/ 了解更多
信息我发布的链接也有 CRUD 操作示例......
PSS。 IQueryable 是重点......
I was writing a Restfull API in MVC and found ODATA. Great implementation by MS.
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api
is where you can get a great start on odata.
i looked at this page
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/getting-started-with-odata-in-web-api/create-a-read-only-odata-endpoint
and was up and running in no time.
Hope this helps. Such a nice thing to work with designing and consuming.
www.odata.org/ for more info
PS. the links i posted have CRUD operation examples as well....
PSS. IQueryable is the point.....
我将以一些简单的方式对其进行解释,希望对您有用。
1) 创建空的控制台应用程序。
2) 对任何公共 OData 服务进行服务引用。即 http://services.odata.org/northwind/northwind.svc/
此后,Visual Studio 将添加更多程序集引用,如下所示
3) 编写以下代码
4) 在Main方法的末尾设置断点。现在调试应用程序。
您将看到类别列表。
5) 如果 OData 已公开并有权实现所有CRUD 然后你就可以做到。
当然,您可以在 ASP .NET MVC 中返回响应,但首先您必须将其转换为模型类。
也许您可以保持静态 DataServiceContext ctx = new DataServiceContext(new Uri("http://services.odata.org/northwind/northwind.svc/"));
在您的 BaseController 类中。
而且您还可以获得如下属性值:
PS 看看这个视频 http://www.youtube.com/watch?v=e07TzkQyops 以及。
I am going to explain it in some simple way and I hope it will useful for you.
1) Create empty Console application.
2) Make a service reference to any public OData service. I.e. http://services.odata.org/northwind/northwind.svc/
After this Visual Studio is going to add some more assembly references like you can see below
3) Write the following code
4) Setup a breakpoint at the end of the Main method. And now debug application.
You are going to see the list of Categories.
5) If the OData have exposed with permission to realize all CRUD then you can do it.
And surely you can return
response
in ASP .NET MVC but first you have to transform it into your Model class.Perhaps you can keep static
DataServiceContext ctx = new DataServiceContext(new Uri("http://services.odata.org/northwind/northwind.svc/"));
in your BaseController class.
And also you get property value like this:
P.S. Take a look at this video http://www.youtube.com/watch?v=e07TzkQyops as well.