Franc Stratton's .NET (TM) Web Application, OOP, and SOA Architecture & Programming Site

A site devoted to ASP.NET (TM), SilverLight (TM) and Browser-Based WPF (TM) Applications, IIS Services, and OOP Architectures

Home     .NET Security     Standards     Data Store     Windows Form Apps     WF/WCF/WPF     jQuery     C# Developer Corner     Java Development     Site Map      
Architecture Overview
N-Tier Architecture
Service Oriented Architecture
SOA Virtualization
Base Classes
BLL
DAL
Base Page
DALFactory
IDAL
Email
Application
Contact Us
Business Entities
Business Entities (Business Objects):

NET development involves implementing business processes that include business objects like employees, customers, inventory, and sales that perform, result from, or are acted on during. In this framework, business objects are passed between the layers - page code-behind, business logic, and data access layers. A business object or entity class in .NET C# might look like:
 

namespace MyNameSpace.Entities

{

#region Class Using References

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

#endregion Class Using Reference

//---------------------------------------------------------------------------

/// Namespace: MyNameSpace.Entities

/// Base Class:

/// Author: Your Team

/// Date: 10/1/2010

/// Updated:

/// <summary>

/// Purpose: A business object representing a class instantiated to pass

/// between layers as method parameters.

///

/// </summary>

//---------------------------------------------------------------------------

public class Person

{

    #region Properties

        public int ID { get; set; }

        public string LastName { get; set; }

        public string FirstName { get; set; }

    #endregion Properties

 

    #region Class Constructors

    public Person(int id, string lastName, string firstName)

    {

         this.ID = id;

         this.LastName = lastName;

         this.FirstName = firstName;

    }

    #endregion Class Constructors

}

}

 

The above business class object has a constructor, but a constructor is not required. The constructor makes creating a generic list of this business object straight-forward when populated by a SQL Server reader. For example, if a search on person is done on last name, the data access layer method would look like:

 

//---------------------------------------------------------------------------

/// <summary>

/// Method Name: GetPersonByLastName

/// Description: Gets user id based on RACFID and Password.

/// </summary>

///

/// <param name="personLastName">Person Last Name</param>

/// <param name="connectionString">database connection string</param>

/// <returns>Generic List of Person Objects</returns>

//---------------------------------------------------------------------------

public List<Person> GetPersonByLastName(string personLastName, string connectionString)

{

   var personList = new List<Person>();

   SqlDataReader rd = null;

   this.ProviderType = AppBase.DataProvider.SqlServer;

   this.ConnectionString = connectionString;

   this.CreateParameters(1);

   this.AddParameters(0, "@LastName", personLastName); //person last name

   this.Open();

   rd = (SqlDataReader)this.ExecuteReader(CommandType.StoredProcedure, SP_GETPERSONBYLASTNAME);

   while (rd.Read())

   {

      personList.Add(new Person(Convert.ToInt16(rd["ID"].ToString()), rd["LastName"].ToString()), rd["FirstName"].ToString()));

   }

   rd.Close();

   rd = null;

   this.Close();

   this.Dispose();

   return personList;

}

 

Notice that the generic list is populated with rows of person objects that match the last name resultset from the database stored procedure call. The SP_GETPERSONBYLASTNAME stored procedure is a string constant in the properties section of the DAL. Also notice that the generic list of person objects is passed back from the DAL method (return personList) to the Domain Business Logic Layer.
 

//---------------------------------------------------------------------------

/// <summary>

/// Method Name: GetPersonListByLastName

/// Description: Gets user id based on RACFID and Password.

/// </summary>

///

/// <param name="lastName">person last name</param>

///

/// <returns>Generic List of person rows to calling page code-behind</returns>

//---------------------------------------------------------------------------

public List<Person> GetPersonListByLastName(string lastName)

{

    var dalLayer = new DAL();

    Entities.Application appInfo = new Entities.Application();

    appInfo = (Entities.Application)HttpContext.Current.Application["AppInfo"];

    string sqlConnString = Decrypt3DES(appInfo.SyncConnectionString, true);

    appInfo = null;

    return dalLayer.GetUserIDFromRACFID(lastName, sqlConnString);

}

 

Notice the appInfo application variable containing the encrypted database connection string is retrieved and decrypted in the business logic layer, this method passes the connection string and last name to the DAL method.  Since the DAL method populates the generic list and returns it, the BLL method ret urns it to calling method in the page code-behind. The page code-behind then populates an oBout grid.
 
 

//Instantiating class

var bll = new SearchBLL();

//Creating generic list object

var list = new List<Person>();

try

{

    //set list to generic list returned from method

    list = bll.GetPersonListByLastName(this.txtLastName.Text);

    //setting grid datasource equal to generic list returned from class method

    grdPerson.DataSource = list;

    //binding grid

    grdPerson.DataBind();

}

catch (Exception ex)

{

    //if Session["MP_UserID"] is not null, set the UserID property to what is returned by the UserID session variable.

    logError.UserID = this.userID != 0 ? this.userID : 1;

    //Setting the module property equal to the method that is firing the error

    logError.Module = "Search.BindPagingGrid()";

    //settting the Description property equal to the exception message being thrown

    logError.Description = ex.Message;

    //calling a method to the evLogger service, passing the logError object, and the application end point.

    evLogger.InsertARTSError(logError);

    //Showing the user a friendly message that an error has occurred..

    this.lblError.Text = "An error has occurred accessing the database. Please contact your supervisor.";

}

finally

{

  bll = null;

  list.Clear();

  list = null;

}

return;

 
By using a business object or entity to pass between the layers, the developer can change the properties of the business object class and not have to change the methods in the DAL, BLL, or code-behind methods.