Pages

Ads 468x60px

3 TIER ARCHITECTURE IN ASP.NET MVC | DAL BAL


Hi, Currently I am learning ASP.NET MVC.. and I am going to tell us the way that how to implement 3 tier architecture in ASP.NET MVC using Class library.
I always use 3 tier architecture  in my projects.. So here in ASP.NET MVC I want to implement same 3 tier architecture . 
(I only describe about the DAL andPresentation layer,  you can yourself implement BAL)
This article purpose is to describe how you will create models in Data access layer (DAL) and access them in Presentation layer...

So lets start...

First open visual studio..(you must have MVC 3.0 installed) and create an new project.



Select ASP.NET MVC 3 web app..


Select Internet App.. 



Now right click on solution and add net project as a class library...
we will use this class library as your Data Access Layer (DAL)


Now right click on DAL and add a folder with name "Models"

 Now we are going to add models classes by using ADO.net Entity data Model(Data first approach)



Select ADO.NET Entity Data Model....



Give your server name and select the database...



Select the tables...

Now you can see that Model1.edmx and App.Config is created...
Model1.Designer.cs file will containing all the models and App.Config file contain the connection string....

This is the App.config file...
you need to copy this connection string and add this connection string in web.config in presentation layer....


This is the web.config file code... paste here the connection 


Now right click on DAL and build it...


Now add the reference of DAL in Presentation layer....


Reference added....


Now add a controller....



Now add a view.... for this right click on Index() and click on "Add View"


Now click on "Create a strongly-typed view" check box....
and here you can see all the model classes are accessible from DAL
So it was your goal to create the Models in DAL and access models in  Presentation layer

No comments:

Post a Comment