Click here to Skip to main content
15,886,756 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
can i do n-tier architechtur in asp.net websites.??
i tried but failed in referencing correctly layers
{Dll,Entities,Dal and website project.}

i did like this.
dal has entity,
bll has entity and Dal,
entity has no layer reference ,
website has entity and bll as referece .
 but when i try to write
using bll;
using entity;


bll is not shown in intellisense and gives error.
but dll and entity gives no error.
i did this again starting over all again.
but getting same problem.

i cant use bll in default.aspx.cs
there must be something wrong.
help please.
Posted
Updated 26-Jul-16 7:43am
v2
Comments
Sergey Alexandrovich Kryukov 3-Mar-15 1:44am    
Not clear. Aren't you mixing up layers and tiers? :-)
—SA
varun150 3-Mar-15 2:09am    
please suggest me i dont know what i am doing.

Yes you can.
First, create a Repository class. Put it in the DAL folder. The repository constructor will instantiate an object(context) of the Entity model you have. It will contain all the methods you use to retrieve, save and update data.
Next, create a BLL folder and place all your extended partial classes and all other classes you created that will be used to decide which data to return to the content page based on passed in parameters. These methods will instantiate an object of the repository and the call the repository methods. If a class accesses the repository and then does anything with the data like parse, filter, send in parameters, it should be in the BLL.
Third, On your content pages, use the ObjectDataSource control to attach the select, update, delete methods to the BLL classes and methods. The topic is large and not for beginners, but learn it and do it! It will be well worth it.

Example of the ObjectDataSource control markup in content page:
XML
<asp:objectdatasource id="ImagesObjectDataSource" runat="server" typename="BLL.ImageData" xmlns:asp="#unknown">
        DataObjectTypeName="BLL.ImageData" SelectMethod="GetAllPhotos" DeleteMethod="DeleteImage"
        UpdateMethod="UpdateImage" OnUpdated="ImagesObjectDataSource_Updated" OldValuesParameterFormatString="orig{0}"
        OnUpdating="MappImagesObjectDataSource_Updating" OnDeleted="ImagesObjectDataSource_Deleted"
        ConflictDetection="CompareAllValues">
        <SelectParameters>
            <asp:querystringparameter name="imageID" querystringfield="imageID" type="String" />
        </SelectParameters>
        <updateparameters>
            <asp:parameter name="ImageData" type="Object" />
            <asp:parameter name="origImageData" type="Object" />
        </updateparameters>
    </asp:objectdatasource>

As you can see from the ObjectDataSources' DataObjectTypeName and TypeName properties that they are connected to the BLL.ImageData class. The BLL.ImageData class has methods to get and process the data returned from calling repository methods.

That is ASP.Net web site N-Tier in a nut shell. Of course there are many implementations. But your logical layers are there.

Search for using the ObjectDataSource control for more information.
 
Share this answer
 
Comments
Louis Lakser 27-Jul-16 13:48pm    
Whoever down voted this has no solution?
varun150 17-Oct-16 0:43am    
this is very old question but thankyou for answering as it gives a nice alternative way.,
Hi,

Change the Access modifiers for your Layer Class.

Normally i suggest

DAL Classes and methods are internal ,So only access with in Same NameSpace

C#
internal class DataLayer
{
  internal static void SaveToDB(string query)
  {
    
  }
}


And BAL Methods are Public, so you can access in Webform by adding 'using BAL;'
C#
public class Employee
{
 public void AddEmployee()
 {
 }
}



Thanks

Siva Rm K
 
Share this answer
 
Comments
varun150 3-Mar-15 2:48am    
can you tell me why cant i reference bal in default.aspx.cs
like using bal;
rmksiva 3-Mar-15 5:35am    
You have to add BAL class library as reference to the website . Right click on Website Name on Object Explorer- > Add Reference -> Project Tab - --> Add
varun150 3-Mar-15 5:42am    
so sorry,sir i had only one class in bal project and i forgot to add that class in namespace thats why i was gettin error on while writng Using Bal at default.aspx.cs despite having at as a reference in wesite.
thankyou so much for your response you get me ideas

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900