简体   繁体   English

使用DAAB 3.5 / 4.0的DAL设计

[英]DAL design using DAAB 3.5/4.0

I'm working on a .Net 3.5 web application.It has various modules say for example Customers,Orders,etc.... I need to a design Data Access Layer (DAL) for the same using Enterprise Library 4.0 (using Data Access Application block or DAAB) to connect to SQL Server 2005. Here is how i plan to go about it: 我正在使用.Net 3.5 Web应用程序。它具有各种模块,例如客户,订单等。我需要使用Enterprise Library 4.0(使用数据访问)来设计相同的数据访问层(DAL)。应用程序块或DAAB)以连接到SQL Server2005。这是我计划进行的工作:

• Have an interface called "IDataService".It will have members like "ExecuteReader()","ExecuteScalar()","ExecuteNonQuery()", "AddParams",etc...basically, this interface will almost look like that of DAAB. •有一个名为“ IDataService”的接口。它将具有诸如“ ExecuteReader()”,“ ExecuteScalar()”,“ ExecuteNonQuery()”,“ AddParams”等成员,基本上,该接口看起来将类似于DAAB。

• Have a class called "DataService" which implements this interface.This class will act as a wrapper over DAAB and each of the method will use the corresponding method in DAAB internally. •具有一个名为“ DataService”的类,该类实现了此接口。此类将充当DAAB的包装,并且每个方法将在内部使用DAAB中的相应方法。

• Have Business classes(or Data Containers) like Customer,Data, etc which will have properties mapping to their corresponding tables attributes in the database. •具有业务类(或数据容器),如客户,数据等,这些类将具有映射到数据库中相应表属性的属性。

• Have DAL classes for each module like CustomerDataService, OrdersDataService, etc.Each of these classes will have constructor code in which I will instantiate DataService class as below: IDataService dataService= new DataService() Also, each of these classes will have methods like: GetCustomerDetails() AddCustomer() RemoveCustomer() UpdateOrder etc. These methods will internally use "dataService" object to make any operation on the database ExecuteReader,ExecuteNonQuery, etc •每个模块都有DAL类,例如CustomerDataService,OrdersDataService等。这些类中的每一个都将具有构造函数代码,在其中将实例化DataService类,如下所示:IDataService dataService = new DataService()此外,这些类中的每一个将具有类似的方法: GetCustomerDetails()AddCustomer()RemoveCustomer()UpdateOrder等。这些方法将在内部使用“ dataService”对象对数据库执行任何操作ExecuteReader,ExecuteNonQuery等

• Have a mapper class for each module like "CustomerMapper","OrderMapper",etc. •为每个模块(例如“ CustomerMapper”,“ OrderMapper”等)都有一个映射器类。 These class will take datasource(for example IDataReader) as input and would fill in the data in the generic collection (List). 这些类将数据源(例如IDataReader)作为输入,并将数据填充到通用集合(列表)中。 And these mapper classes will be internally called by the corresponding Dataservice class to return the type-safe collection to the calling client. 这些映射器类将由相应的Dataservice类在内部调用,以将类型安全的集合返回给调用客户端。

• Have a helper class like DbHelper which will do tasks like "handling DBNull cases","storing stored procedure names",etc. •有一个类似DbHelper的帮助程序类,它将执行诸如“处理DBNull情况”,“存储存储过程名称”等任务。

• DataService classes will be inturn used by the BusinessLogic layer classes...ie CustomerBusiness,OrdersBusiness,etc. •DataService类将由BusinessLogic层类依次使用...即CustomerBusiness,OrdersBusiness等。

• Business Logic layer will return the collection to the presentation layer . •业务逻辑层将集合返回到表示层。

Does this design make sense?What are the advantages/disadvantages of this approach? 这种设计有意义吗?这种方法的优点/缺点是什么? The advantage I could think of this approach is that all DataService classes will alway program against the interface "IDataService" without needing to know how "DataService" class is implemented internally.So in the future,if i remove DAAB and use another API inside my DataService class, the client code need not change. 我可以想到的这种方法的优点是,所有DataService类都将始终针对“ IDataService”接口进行编程,而无需知道内部如何实现“ DataService”类。因此,将来,如果我删除DAAB并在内部使用另一个API DataService类,不需要更改客户端代码。 Also,I can add any method in my IDataService interface which is not present in DAAB....for example BatchUpdate()... 另外,我可以在IDataService接口中添加DAAB中不存在的任何方法。...例如BatchUpdate()...

Please correct me if i am wrong. 如果我错了,请纠正我。

It looks like you are making it complicated than it should be. 看起来您正在使它变得比应有的复杂。 Maybe take one step at a time would help. 也许一次采取一个步骤会有所帮助。

DAL: I don't see the benefits of having a wrapper over DAAB. DAL:我看不到DAAB有包装纸的好处。 IMO, DAAB is already a DAL wrapper. IMO,DAAB已经是DAL包装器。 Wrapper over wrapper is counter productive. 包装上的包装适得其反。 There should be only one DAL. 应该只有一个DAL。 That's the whole point of DAL. 这就是DAL的重点。

ORM: For mapper class, perhaps you should consider using Entity Framework or NHibernate for ORM. ORM:对于mapper类,也许您应该考虑使用Entity Framework或NHibernate for ORM。 Code your own ORM is tedious and hard to maintain when schema evolves. 模式发展时,编写自己的ORM既繁琐又难于维护。

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

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