locked
3-tier architecture RRS feed

All replies

  • User-1946294156 posted

    So the 3-tier in a web site stands for the Presentation Tier, the Business Logic Tier, and the Data Access Tier.  The tutorials that you are looking at are one of several ways to create these Tiers.  In other plateforms, the 3 Tiers require alot more work to create this.  But back to .NET, the Data Access Tutorials show you ADO.NET, which is available in all versions of .NET; however, LINQ to SQL was introduced in 3.0 and is currently avaliable today.  And even newer is the Entity Framework that was introduced in the 4.0 release of .NET.  All of these are Data Access Layers for .NET.

    So, the Business Logic Layer (Tier) is the Tier where all the business decisions are made.  A business decision is any decision needed to process the data that is not part of the requirments of the database.  For example, a price column may require that the price is not null; however, part of the business requirements state that a person with x access can enter a value more than 20 dollars more than what was there.  This rule is what the Business Logic Layer deals with.  The Business Logic Layer basically interacts with the Data Access Layer, but never the Database. 

    To learn how to make your own Data Access Layer, you will want to chekc out Data Sets, and this is not the file, but the actual code that handles data.  Check out this site for tutorials:

    http://csharp.net-informations.com/dataset/csharp-dataset-tutorial.htm

    Saturday, June 11, 2011 7:58 PM
  • User-604637671 posted

    Thanks bobj181,

    I'll read through the tutorials. I've actually created this website with tableadapters and adhoc sql, table adapters and stored procedures, and in the entity framework. I'm eally just wanting to learn it all. Here's a snippet from my BLL. It accesses my table adapter for my Assets table, uses GetAssets, which has a stored procedure to pull the information from my DB. I'm using a relational DB desing that's normalized pretty well, so I am pulling related data from other tables and presenting values from those tables instead of theit Primary key values. So, with that said, could you provide a simple code snippet showing me how I would access the same data in a dedicated DAL for the Assets table. Here's the snippet and the SP

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using NetOpsTableAdapters;
    
    [System.ComponentModel.DataObject]
    /// <summary>
    /// Summary description for AssetsBLL
    /// </summary>
    public class AssetsBLL
    {
        private AssetsTableAdapter _assetsAdapter = null;
        protected AssetsTableAdapter Adapter
        {
            get
            {
                if (_assetsAdapter == null)
                    _assetsAdapter = new AssetsTableAdapter();
    
                return _assetsAdapter;
            }
        }
    
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public NetOps.AssetsDataTable GetAssets()
        {
            return Adapter.GetAssets();
        }
    
    ====== The Stored Procedure =====
    ALTER PROCEDURE [dbo].Assets_Select
    AS
    	SET NOCOUNT ON;
    SELECT AssetID, Assets.ProductID, Assets.SiteID, Assets.StatusID, Assets.RowID, Assets.RackID, Assets.DeptID, Assets.PhysVirtID, HostName, ISTContact, CustomerContact, ServicesProvided, Dependancies, Assets.PatchScheduleID, Assets.TestSuiteID, EnrolledInBackups, PropertyNum, SerialNum, PONum, EOL,
    
    Products.Model AS Model,
    Sites.SiteName AS Site,
    Status.Status AS Status,
    Row.Row AS Row,
    Rack.Rack AS Rack,
    Department.Department AS Department,
    PhysVirt.ServerType AS ServerType,
    PatchSchedule.Schedule AS Schedule,
    TestSuite.TestSuite AS TestSuite
    
    FROM Assets
    
    JOIN Products ON
    Products.ProductID = Assets.ProductID
    JOIN Sites ON
    Sites.SiteID = Assets.SiteID
    JOIN Status ON
    Status.StatusID = Assets.StatusID
    JOIN Row ON
    Row.RowID = Assets.RowID
    JOIN Rack ON
    Rack.RackID = Assets.RackID
    JOIN Department ON
    Department.DeptID = Assets.DeptID
    JOIN PhysVirt ON
    PhysVirt.PhysVirtID = Assets.PhysVirtID
    JOIN PatchSchedule ON
    PatchSchedule.PatchScheduleID = Assets.PatchScheduleID
    JOIN TestSuite ON
    TestSuite.TestSuiteID = Assets.TestSuiteID
    Sunday, June 12, 2011 8:15 AM
  • User-1946294156 posted

    So there are many ways to pass data between methods.  Here is a snippet from the ASP.NET Tutorials:

    [System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Select, true)] 
    public Northwind.ProductsDataTable GetProducts()
     { return Adapter.GetProducts(); } 
    
    [System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Select, false)] 
    public Northwind.ProductsDataTable GetProductByProductID(int productID)
     { return Adapter.GetProductByProductID(productID); } 

    However, to go along with the new SOA standard, I create a method that returns an array or some type of data structure to the calling method.  This allows me to have any application if it is housed in WCF or method if it is internal to an application call the method, and not requiring a lot of overhead to process or convert the data.

    Sunday, June 12, 2011 8:53 AM
  • User-1269009881 posted

    Hi gmagerr,


    I think you could refer to the following links to get started.

    #3-tier architecture in asp.net with C#

    http://www.dotnetfunda.com/articles/article71.aspx

    #Creating a Data Access Layer

    http://msdn.microsoft.com/en-us/library/aa581776.aspx#aspnet_tutorial01_dataaccesslayer_cs_topic3

     

    Best regards,
    Peter

    Tuesday, June 14, 2011 5:47 AM
  • User-843484705 posted
    These will be very helpfull to you

    3-tier Architecture with ASP.NET 2.0:

    http://msdn.microsoft.com/en-us/library/aa581769.aspx

    Building an N-Tier Application in .NET: 

    http://msdn.microsoft.com/en-us/library/ms973279.aspx

    and more http://forums.asp.net/p/1572880/3947439.aspx#3947439
    http://forums.asp.net/p/1602739/4084792.aspx#4084792
    The business Login layer for writing property etc.
     and the DataAccesslayer to communication database.


    Thursday, June 16, 2011 7:19 AM
  • User1563021683 posted

    Just out of curiosity, if you want to create an object for every table in your database, why can't you adapt the entity framework? Seems like a better option to me

    http://msdn.microsoft.com/en-us/library/aa697427(v=vs.80).aspx

    Saturday, June 18, 2011 11:31 AM
  • User-604637671 posted

    Thanks sujithgokul,

    I have created this site in VB, C# Entity framework, I've done TableAdapters with Ad Hoc sql queries and stored procs, and now I want to learn how to create the DAL classes for each table. It's just a learning experience for me.

    Saturday, June 18, 2011 2:12 PM
  • User1563021683 posted

    In my experience, you just need a wrapper than a concrete data access layer (if at all required). Have a look at this blog. This may answer few of your questions http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx

    Thursday, June 30, 2011 4:40 AM