通用DAO架构

时间:2014-04-11 04:35:11

标签: c# .net architecture data-access-layer

我们目前有客户端将数据存储在多个数据源中(MS SQL,Oracle,MS Access,Web服务等)。

我们已经创建了一个框架来处理MS SQL,Oracle,Access的大多数方案,但是有些客户端不愿意提供直接的数据库访问,因此只提供Web服务。

我无法想出一个通用的解决方案来处理手头的5%问题,为Web服务创建一些东西作为数据源,以及其他人。

有人可以帮我解决这种情况。

-Naga

2 个答案:

答案 0 :(得分:3)

将您的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.
  }
}

答案 1 :(得分:0)

我认为其中一个选择是使用存储库模式。看看Repository模式示例:http://www.remondo.net/repository-pattern-example-csharp/

我希望这会有所帮助。