简体   繁体   English

通用数据访问层

[英]Generic Data Access Layer

I want to build a generic data access layer targeting any multiple databases ie SQL Server, Oracle, DB2, etc, and the tricky part is that I need to also support Web Services, so my datasource can also be a Web Service. 我想构建一个针对任何多个数据库(即SQL Server,Oracle,DB2等)的通用数据访问层,而棘手的部分是我还需要支持Web服务,因此我的数据源也可以是Web服务。 Each of the data sources have similar data but the column names are different and the return type(s) are different in the web services as well. 每个数据源具有相似的数据,但是Web服务中的列名不同,返回类型也不同。

How can i create a generic Data access layer to target any datasource and return a generic object/list to the UI in .NET, C#. 我如何创建通用数据访问层以任何数据源为目标,并在.NET,C#中向UI返回通用对象/列表。

.NET 4.5, C#, Web API, VS 2013 is what i am using. 我正在使用.NET 4.5,C#,Web API,VS 2013。

Please suggest. 请提出建议。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

cheers 干杯

You are making things way too complicated in my opinion. 在我看来,您使事情变得太复杂了。 Just create data access components for every data source type you have, and have them return business or domain entities that you define. 只需为您拥有的每种数据源类型创建数据访问组件,然后让它们返回您定义的业务或域实体。 Use the power of each data source to its fullest instead of trying to make them 'generic'. 充分利用每个数据源的功能,而不是尝试使其成为“通用”数据源。

Also, why treat a web service as a data source? 另外,为什么将Web服务视为数据源? It's a web service, already abstracted out. 这是一个已经抽象出来的Web服务。 Just use it in your application layer and use its entities. 只需在应用程序层中使用它并使用其实体即可。

Bottom line: if it's too hard to do, then don't do it and keep it simple. 底线:如果做起来太难了,那就不要做,要保持简单。

Also read http://ayende.com/blog/4567/the-false-myth-of-encapsulating-data-access-in-the-dal . 另请阅读http://ayende.com/blog/4567/the-false-myth-of-encapsulating-data-access-in-the-dal

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

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