设计并实现用于ASP.NET一个通用的数据存取层应用程序 原作者 Paul Abarham 翻译 firstname.lastname@example.org
发表于2004/2/17 18:46:00 1144人阅读
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)
在此文中，我们将深入研究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来跟随本文进行操作。
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
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.
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.
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
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 for the business logic tier
Assembly for the data access tier
contents a HttpModule to trace errors in the presentation layer
Contents typed datasets which serve as a vehicle to transport data between the tiers
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)
- 在15分钟内用ASP.Net MVC创建一个电影数据库应用程序
- 部署一个安全的ASP.NET MVC 5应用程序成员、OAuth和SQL Azure网站数据库
- ASP.NET MVC 环境下CKeditor 的配置以及用jQuery进行数据存取操作
- 译文：使用MVC5的Entity Framework 6入门（七）——为ASP.NET MVC应用程序读取相关数据
- 译文：使用MVC5的Entity Framework 6入门（八）——为ASP.NET MVC应用程序更新相关数据
-  使用 MVC 5 的 EF6 Code First 入门 系列：为ASP.NET MVC应用程序读取相关数据