SIGN UP MEMBER LOGIN:    
ARTICLE

ADO .NET Evolution: Part II: 2-Tier to 3-Tier

Posted by Balakrushna Swain Articles | Design & Architecture August 09, 2011
Implementation and example of a 3-Tier Application.
Reader Level:

In my previous Article ADO .NET Evolution: Part I: 2-Tier to 3-Tier I have explained the mistakes we make when developing  ADO .Net applications.

Here in this Article I will try to explain a real implementation of the 3-Tier Application with an example. You might be thinking "During this new era of Data Access Technology what is the need of learning a Basic 3-Tier Application development process?" Yes you are correct, but before implementing any new .Net Design Patterns like LINQ,
Entity Model, MVC, MVP or MVVM we need to understand the basics of 3-Tier Application.

Basic Rules and Concept of 3-Tier Application

  1. There will be clear separation of layers. such as Presentation Layer, Business Logic Layer, Data Access Layer and Entity Layer.
  2. This kind of separation of layers will give the facility to host Business Logic in Business Server and Data Access in Database Server.
  3. Data Encapsulation done by Entity Layer which can serialized across the layer, from Presentation to Business and Business to Data Access and vice versa.
  4. Business Logic will encapsulated in Business Logic layer.
  5. Data Access process and Security will be encapsulated in Data Access Layer.
  6. Finally the Presentation Layer will access only the Business Logic Layer to Add a new record, Modify an existing record, to View records by list or a particular Record.
  7. Presentation Layer will never communicate directly with Database Object or Data Access Layer.
This Article will also guide you the Path way to develop a 3-Tier Application with some simple Steps.

Step - 1

Add 4 Projects to an empty Visual Studio Solution. Of of these, 3 of the projects should be a Class Library (For Class Library the output will be a dll) and the other one can be your application (Windows Form Application or Web Application or Web site). You should follow a better naming convention for the projects. For example you can have your projects in your Solution like this.

Projects
Application
Type of Project

Entity
ApplicationName.Entity
Class Library
DAL
ApplicationName.DAL Class Library
BLL
ApplicationName. Class Library
Application
Application Win/Web Application/Site

So now the Solution Explorer will looks like this.

solution_explorer.png


Step - 2
Now add Entity classes to the Entity Project. A simple Entity Class will look like this.
entity.png

Step - 3

Add a reference of Entity to the DAL Project, so we can access the Entity Classes within the DAL. Inside a DAL class you can write methods to access and to manipulate data from a Database. A simple DAL class can have all the following methods:

dal_members.png

In the Attached Sample code you can find the code for DAL, but for understanding purposes see the Upsert method bellow, which insert/Update a record in Database. (To know more about Upsert Method Read my previous Article How to: Implement UPSERT () Method in C#).
dal_upsert.png

And the Select Method will look like this.
dal_select.png

Step - 4

Now add Classes to BLL for each Entity and you can have the methods list like this. Before that do not forget to add reference from Entity and DAL.

bll_members.png


Step - 5
So you are done with the Entity Layer, Data Access Layer and Business Logic Layer. Now you can add a very good look and feel and user friendly UI as the Presentation Layer.
To access the Entity and Business Logic layer add references from both the projects.

  • In your Save button Click event you can create an object of BLL and can call the Add() method of it.
add_new.png

  • To modify an existing record you can call the Edit() Method of BLL.
modify.png

  • And to bind data to a GridView you can call GetList() Method.
bind_grid.png

So cheer up... now your old 2-Tier Application is ready with a new Flavor of 3-Tier Architecture.

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, Thanks for the article but it would be good if i get the same example in VS 2008

Posted by B M Suchitra Nov 07, 2011

Very good article :) Thanks

Posted by anas AlQudah Sep 04, 2011

Good article. keep it up...

Posted by Rohatash Kumar Aug 10, 2011

Yes you are absolutely correct. This application is being generated by one of the automated tool (.net Code Engine - visit this link for more information: http://www.dotnetcodeengine.com), which is one of my product. So this kind of mistake is there in the tool it self. I will always try to avoid this kind of mistake in future. Thanks a lot for evaluating the article.

Posted by Balakrushna Swain Aug 09, 2011

Hi Swain, Appreciate your efforts and have a suggestion/question. At the end of Step 3, there is a conversion toString and casting back? Have you tried to read the values from datareader in their native data type which can save one conversion and not blowing program out of resuorces incase this model is followed for an enterprise application. Thanks.

Posted by knights Aug 09, 2011
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor