[英]Build OData API without Entity Framework
I have an existing web forms project which consists of 3 different projects: UI layer (Web project), Business Logic Layer and Database Project. 我有一个现有的Web窗体项目,该项目包含3个不同的项目:UI层(Web项目),业务逻辑层和数据库项目。 I have already written the data access methods which connect to the database and return data to the business logic layer.
我已经写了连接到数据库并将数据返回到业务逻辑层的数据访问方法。
Now we need to provide a REST API, and I was thinking of using oData API along with REST. 现在我们需要提供一个REST API,我当时正在考虑将oData API与REST一起使用。 But all the examples I have seen use Entity Framework and I just cannot use Entity Framework because our data access layer returns data to the business layer, which then processes that data and adds some logic, and then present it to the UI layer.
但是我看到的所有示例都使用Entity Framework,而我不能使用Entity Framework,因为我们的数据访问层将数据返回到业务层,然后业务层处理该数据并添加一些逻辑,然后将其呈现给UI层。
Can I still use oData API? 我仍然可以使用oData API吗? If yes, then will I need to create fresh methods manually for each of the complex query of oData API?
如果是,那么我是否需要为oData API的每个复杂查询手动创建新方法? How will OData API access my BL Layer?
OData API如何访问我的BL层?
You can do this (I have just done similar myself) but it is very hard work. 您可以做到这一点(我自己也做过类似的事情),但这是非常艰巨的工作。
To me, OData always felt like a way of exposing the entity framework through web services so if you were to try and implement it without the entity framework you will end up spending a lot of time parsing queries to your data access layer. 对我而言,OData始终感觉像是一种通过Web服务公开实体框架的方法,因此,如果您尝试在没有实体框架的情况下实现它,则最终将花费大量时间将查询解析到数据访问层。
If you do decide to go down this route, maybe consider only implementing part of the OData spec - work out which parts you actually want to be able to use - as it is huge and the task is daunting. 如果您确实决定走这条路,也许考虑只实现OData规范的一部分-确定您真正想使用的哪些部分-因为它庞大且任务艰巨。
These are only from my experiences though and you may have a better data access layer API setup than I had when I started which could make things significantly easier. 不过,这些只是我的经验,与开始时相比,您可能具有更好的数据访问层API设置,这可以使事情变得更加容易。
EDIT to answer last question: 编辑以回答最后一个问题:
Will you need to create fresh methods manually for each of the complex query of oData API? 您是否需要为oData API的每个复杂查询手动创建新方法? This will really depend on how your data will be exposed and how your data access layer is setup.
这实际上取决于如何公开您的数据以及如何设置数据访问层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.