通用DAL建筑

Generic DAL Architechture
2021-03-07
  •  译文(汉语)
  •  原文(英语)

当前,我们有客户端将数据存储在多个数据源(MS SQL,Oracle,MS Access,Web Services等)中.

我们已经创建了一个框架来处理MS SQL,Oracle,Access的大多数情况,但是某些客户端不愿提供直接的DB访问,因此仅提供Web服务.

我无法提出一个通用的解决方案来处理5%的问题,从而无法将Web服务与其他资源一起创建为Web服务.

有人可以帮助我如何处理这种情况.

-长

速聊1:
你是什么意思generic solution?最好的方法是提供对上层DAL的直接访问(通过WCF / Web服务),该访问将访问下层DAL(DB).
速聊2:
谢谢你快速的回复.我将尽力为您提供更多所需的信息.如果我有6个客户端,则每个客户端都使用不同的方式存储数据,即MSSQL,Oracle,Web服务等.我们可以编写一个通用DAL层来覆盖SqlClinet,OleDb,ODBC,但是缺点是遇到一个网络服务.我们如何为Web服务创建DAL.点击用于Web服务的DAl并获取要在UI中显示的数据.
解决过程1

将您的Web服务数据源与MS SQL或Oracle数据源一样对待.它只是一个附加的具体数据存储.遵循这样的模式:

public interface IRepository
{
 List<EmployeeModel> GetEmployees();
}

这里的EmployeeModel是一个简单的C#类,与Oracle或MS SQL或您的Web服务无关.

public class SqlRepository : IRepository
{
  public List<EmployeeModel> GetEmployees()
  {
   // get it from SQL using ADO.NET or Linq2Sql
   // transform into EmployeeModel using Automapper/manual and return.
  }
}

public class WebServiceRepository : IRepository
{
  private readonly ProxyClient _proxy; // or helper

  public List<EmployeeModel> GetEmployees()
  {
   // get it from the ASMX using Proxy Helpers with return type as data contracts.
   // transform the data contracts into EmployeeModel using Automapper/manual and return.
  }
}
解决过程2

我认为选项之一是使用存储库模式.在此查看存储库模式示例:http : //www.remondo.net/repository-pattern-example-csharp/

我希望这有帮助.

速聊1:
我尝试了Repository,它为我解决了95%的问题,但是问题是5%的数据源是一个具有端点的Web服务,通​​常,我们必须自定义代码以处理n个不同的Web服务端点,我们现在正在尝试提出一种解决方案,以为Web Service端点创建通用DAL并获取数据.我可能错过了一点.您能否详细说明如何将Web Service信息库用作数据源.
速聊2:
:您正在寻找Raja Nadar的答案.

We currently have clients storing data in multiple data sources (MS SQL, Oracle, MS Access, Web Services, etc.).

We have created a framework to handle majority scenarios for MS SQL, Oracle, Access, however some clients are reluctant to provide direct DB access and hence give out only Web Services.

I am unable to come up with a generic solution to handle the 5% problem at hands to create something for the Web Services as the data source, along with others.

Can someone help me how to handle this kind of scenario.

-Naga

Talk1:
What do you mean by generic solution? Best approach is provide direct access to upper layer DAL (through WCF/Web services) which will access lower layer DAL (DB).
Talk2:
Thanks for your quick response. I shall try and give you more input of what i am looking for. If i have 6 clients, each one of them is using different ways to store data i.e. MSSQL, Oracle, Web services etc. we can write a generic DAL Layer to cover SqlClinet, OleDb, ODBC, however the shortcoming is with when we encounter a Web Service. How do we create a DAL for a web service. Hit the DAl for web service and get data to show in UI.
Solutions1

Treat your Web Service data source as no different than MS SQL or Oracle Data source. It is merely one additional concrete data store. Follow a pattern like this:

public interface IRepository
{
 List<EmployeeModel> GetEmployees();
}

here EmployeeModel is a simple C# class, and not tied to Oracle or MS SQL or your web service.

public class SqlRepository : IRepository
{
  public List<EmployeeModel> GetEmployees()
  {
   // get it from SQL using ADO.NET or Linq2Sql
   // transform into EmployeeModel using Automapper/manual and return.
  }
}

public class WebServiceRepository : IRepository
{
  private readonly ProxyClient _proxy; // or helper

  public List<EmployeeModel> GetEmployees()
  {
   // get it from the ASMX using Proxy Helpers with return type as data contracts.
   // transform the data contracts into EmployeeModel using Automapper/manual and return.
  }
}
Solutions2

I think one of the options is to use a Repository Pattern. Have a look at Repository pattern example at this: http://www.remondo.net/repository-pattern-example-csharp/

I hope this helps.

Talk1:
I tried Repository, it solved the 95% problem for me, but the problem is the 5% where the data source is a Web Service with an end point, and in general we have to customize code to handle n different web service end points, we are now trying to come up with a solution to create a common DAL for Web Service end points and get data. I might have missed a point. can you please elaborate more on how can i use Repository for Web Service as a data source.
Talk2:
: answer from Raja Nadar is what you are looking for.
转载于:https://stackoverflow.com/questions/23003587/generic-dal-architechture

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入