Exposing Large Data Models via OData and WebAPI

sis*_*dog 6 asp.net-mvc entity-framework wcf-data-services asp.net-web-api

I have an EF model with about 200 tables, 75 of which I'd like to expose via REST in an MVC app. I started by adding a WCF Data Service (WCF-DS), pointed it to the EF context, and bam, I had the entire database mapped to REST URI's with full OData syntax support in about 2 minutes.

Next I tried to create the same REST URI space with WebAPI. When I tried to add a WebAPI OData Controller the first thing it asks for was a Model Class and when I was done creating the controller (and copying all the required ODataConventionModelBuilder code into the WebApiConfig) I only had one REST endpoint! My impression now is that WebAPI is not well suited to expose entire EF models with a lot of brute force.

So my questions:

  1. Am I missing a way to map a bunch of WebAPI endpoints to a EF model in one fell swoop?

    (Maybe T4 templates that build all the WebAPI code when I generate my EF model??)

  2. Are there any compelling reasons to consider WebAPI vs WCF-DS to expose large URI domains?

    (Some say that the benefits of WebAPI are to have fine grained control over each and every MVC/HTTP request but that seems counter-productive if the goal is to conform to the OData spec. I'm not sure I want to have 75 controllers and 1000's of lines of code that would tempt my dev colleagues to change one entity's behavior that would result in different behavior from other entities.)

    (For cross cutting concerns such as security, caching, or performance throttling WCF-DS seems to have sufficient configure-ability with Interceptors and its DataServiceConfiguration class. Are there any features of WebAPI that would do better here?)

Thanks.

Update: I found this article by Julie Lermon that helps a bit: http://msdn.microsoft.com/en-us/magazine/dn201742.aspx

Vag*_*lov 1

由于我只使用 WCF DS 公开了 EF 模型,因此我无法评论 Web API 问题。但我们从来没有真正的理由将我们的模型的 WCF DS 替换为 Web API,因为您也注意到了,EF 和 WCF DS 配合得很好,您基本上可以免费获得 OData 源。在客户端,情况有所不同:我们从 WCF 数据服务客户端开始,它试图模仿 Linq to Entity Framework,但它有很多限制,以至于我最终编写了自己的 OData 客户端(您可以阅读有关是什么让我们不高兴)此处包含 WCF DS 客户端部分)。

回到服务器端:我们的域很大,我们有 80 多个表,几乎有 1000 列。我们甚至支持使用批量更新的所有 CRUD 操作(事务的 OData 模拟)。虽然由于设计原则,我建议在通过 OData 协议公开数据库记录更新操作之前要三思而后行,但我们在这种方法上没有遇到任何技术问题。