设计并实现用于ASP.NET一个通用的数据存取层应用程序

发表于:2007-06-30来源:作者:点击数: 标签:
Designing and implementing a versatile data access tier for an ASP.NET application By Paul Abarham In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT) Abst
Designing and implementing a versatile data aclearcase/" target="_blank" >ccess tier for an ASP.NET application
By Paul Abarham

In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT)

Abstract



设计并实现用于ASP.NET一个通用的数据存取层应用程序

作者 Paul Abarham 翻译 cwxiao888@163.com



在此文中,我们将深入研究n-tier架构的设计,而且我们将聚焦于DAT (DAT,data access tier) 。

摘要



In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT) (Figure 0).Our goal is to design and implement an appropriate data access tier(DAT) for scalable, reliable and interoperable web application. I have divided this article in to two major parts. In the first part, we will discuss about architectural goals, typed DataSet, EventLogs and HttpModules, which are helpful to understand the second part of this article . We will build in the second part a small(but fine) n-tier application and our focus will be on design and implementation of data access tier. You need a SqlServer (database: Northwind) and VS.net to follow this article.

在此文中,我们将深入研究n-tier架构的设计,而且我们将聚焦于DAT (DAT,data access tier) (Figure 0) 。我们的目标是设计并实现一个可升级的可靠并且相互协同DAT网络应用程序。我已将本文分成两个主要的部分。 在第一部分中,我们将讨论有关于架构的目的,typed DataSet,EventLogs和HttpModules,这有益于理解本文的第二部分。 在第二个部分中我们将创建一个小的(但是很好) n-tier应程序,而且我们的焦点集中在在设计和实现DAT。 你需要一个SqlServer (数据库:Northwind )和VS.net来跟随本文进行操作。

Contents:内容

1. Designing Goals of a data access tier(DAT)DAT的设计目标

1.1 Architectural Goals 架构目标

1.2 Installation of the prototype prototype的安装

1.3 Typed DataSets

1.4 Event Logs

1.5 HttpModules

2.0 Implementing versatile data access tier(DAT) 实现通用的DAT

2.1 Implemeting a super class for data access tier. 实现一个用于DAT的超类(super class)

2.2 A performance test to evaluate SqlDataReader and DataSet objects in the business tier.

评估商业层(business tier)中SqlDataReader 和 DataSet对象的性能测试

2.3 How can I extend this data access tier (DAT) to access multi-databases.

我如何才能扩展此DAT至存取多层数据库(access multi-databases)

2.4 How can I apply database transactions with different isolation level?

我如何应用不同隔离等级(different isolation level)的数据库处理(database transactions)?

2.5 How can I insert and retrieve images?

我怎样插入和检索图象?



Figure 0 shows us a typical 3 Tier Application that is dissected in to three major disjunctive layers, which are data tier (DA),middle tier and presentation tier (PT).

Figure 0给我们展示了一个典型的3 Tier应用,它被分成三个主要的分离层,data tier (DA),middle tier 和 presentation tier (PT)。



If you are not familiar with n-tier architecture, I like to recommend following articles.

http://www.c-sharpcorner.com/Tutorials/Building3TierAppPA.asp

http://www.c-sharpcorner.com/Code/2002/June/AdoNetWinDNAPerspective.asp

如果你对n-tier架构不太熟悉,我给你推荐下列文章。

http://www.c-sharpcorner.com/Tutorials/Building3TierAppPA.asp

http://www.c-sharpcorner.com/Code/2002/June/AdoNetWinDNAPerspective.asp



1. Designing an appropriate data access tier (DAT)

1.0 Architectural Goals

The must requirements of an enterprise application can be expressed through the following buzzwords

Interoperability and Extendibility

Scalability and Performance

Reliability and Manageability

Security

Let us look some of the buzzwords closer, what do they really mean?

Interoperability deals with the ability of a system to communicate with other internal or external systems in a heterogeneous environment . This is a very important issue, because we need information to act just in time to meet needs of our customers and business partners. To achieve this important goal, our system must able to offer and consume web services.

To be agile in your business, sometimes you need to extend your application. If we couple a system so tightly to other systems, then it may trigger a “modify avalanche” (e.g. you pass data to a peer application via email, which represents data tables through comma separated columns. The recipient will open the email and parse it to gain information. Say, if we want add or change a column, then we have to modify other depending systems too because the order of columns have changed).In order to avoid “modify avalanches”, we must couple systems loosely using technologies such like Web services (preciously: XML supported technologies ).

Scalability is a measure which describes the ability of a system to increase performance by adding additional system resources .A system applies following strategies to be scalable.

It must able to allocate new resources to satisfy increasing user requests.

It must use algorithms and data structures which won’t occupy resource for long time.

Scalability is a very important issue, because you can invest in a system with the confidence that the system will grow with the business.

Reliability of a software system can be defined as the probability that a system will perform its task without failure . To achieve higher reliability, a system must provide utilities to track possible errors.



Figure 1 shows partial ER-Diagram of the database Northwind

So, we have now great goals. In order to achieve these goals, we have to lay a proper groundwork. Our data access tier (DAT) must be designed to accomplish the following tasks.

It must enable us to interact with set of data sources and to coordinate transactions among them

It must be flexible to use different data access technologies (SqlDataAdapter and DataSet), because this issue deals with scalability and performance of your system.

It must support presentation tier (PT) to display coherent data tables . Most of interrelated tables of a relational database are modeled according to master-detail (Parent-Child ) relationship . In our database example (see Fig 1), you can find out some these duos and they are: Customers-Orders . Orders-Order Details. There is always a need in the presentation tier(PT) to drill down the master table to expose details. The Figure 2 displays the master-detail relationship Customer-Order .

It must provide infrastructure to trace and analyze errors .



Figure 2 shows a screen shot of the demo web application DAPrototype

1.2 Installation of the prototype

Before we move further, I recommend you to install the sample application DAPrototype, so that you can refer it time to time. The solution DAPrototype.sln consists following class libraries (see Fig 3).

Assembly
Description

BLT
Assembly for the business logic tier

DAT
Assembly for the data access tier

HttpTraceModule
contents a HttpModule to trace errors in the presentation layer

TDS
Contents typed datasets which serve as a vehicle to transport data between the tiers


Figure 3

Please follow these instruction to install the sample application:

Download the file DAPrototype.zip

Create a new ASP.NET C# web application DAPrototype and replace it with the file which you have downloaded.

Open and execute the SQL Script DAPrototype/SqlScript/DAPrototype.sql, in order to create store procedures on the database Nortwind which are part of our data tier (DT)

原文转自:http://www.ltesting.net