NLayers Examples

This article is meant to provide examples of using the NLayers project. You can download the latest NLayers from:

Before proceeding with this article I would recommend reading the previous 2 articles on Installation and Architecture of NLayers.

Example Application

You can download the example application by using the following URL:

Important Classes and Properties from the Web Context

You can see that the Web application project is referring to the Instance Manager. An Instance Manager project contains the static class named WebApp which can be used to access the Business Logic and Data Access properties.



Important Classes and Properties from the Business Logic Context

The Business Logic classes are deriving from BaseBL. The BaseBL provides the following properties.

public class BaseBL
    public IDataAccessAccessPoint DataAccess { get; set; }
    public IBusinessLogicAccessPoint BusinessLogic { get; set; }

Important Classes and Properties from the Data Access Context

The Data Access classes are derived from BaseDA. The BaseDA provides the Entity Framework CRUD wrapper methods like:

  • Insert
  • Update
  • Delete
  • GetAll
  • Where()

Running the Example

Use the following steps to execute the Example Application.

  1. Download the solution from here.
  2. Extract the zip file and open the solution.
  3. Make the NLayersExample.Web project as the startup project.
  4. Locate the Database.sql file inside the web project and execute it against your SQL Server.
  5. Modify the web.config with the SQL Server name.
  6. Execute (F5) the example.

On successful execution you will see the following web page:


The Solution Explorer looks like below:


Example 1: Get All SampleCustomer entities

var list = WebApp.DataAccess.SampleCustomerDA.GetAll();

Example 2: Insert a new SampleCustomer entity

SampleCustomer customer = new SampleCustomer();
customer.Name = "New Customer";
customer.Address = "New Address";

Example 3: Update previous SampleCustomer entity

SampleCustomer customer = WebApp.DataAccess.SampleCustomerDA.Where(c => c.Name ==
       "New Customer").FirstOrDefault();
customer.Address += "Updated";
if (customer != null)

Example 4: Delete the previous SampleCustomer entity

SampleCustomer customer = WebApp.DataAccess.SampleCustomerDA.Where(c => c.Name ==
       "New Customer").FirstOrDefault();
if (customer != null)

Example 5: Access a Business Logic class



The following are the most common scenarios needed to be aware of while working with NLayers.

Scenario 1: Adding a new Entity and associated Data Access classes and Properties

Please use the following steps to do that:

  1. Inside the Entity project, open the EDMX file
  2. Update the Model from database and add the new Entity (Make sure the you uncheck the Pluralize option, otherwise the Data Access wrapper methods won't work as intended)

  3. Create a new interface named INewEntityDA inside the Data Access Interface project.


    Use the following template as shown below:


    The interface provides a decoupling between the Data Access Implementation and Web application projects. The Instance Manager project will be handling the instance creation.
    After adding the interface file, try building the project alone.
  4. Now create the Data Access Implementation class named NewEntityDA inside the Data Access Implementation project.


    Use the following template as shown below:

  5. Build the Data Access Project
  6. Now you can try accessing the new Data Access class through the property WebApp.NewEntityDA as shown below.

    // If the new property is not displayed, try refreshing the project references

Scenario 2: Adding a new Business Logic class

Please follow the steps to do that:

  1. Select the Business Logic project and use Add New Item named NewBL


    You can use the following template:

  2. Build the Business Logic project
  3. Now try accessing the new Business Logic class property from the web application using the WebApp instance manager class.

    // If the new property is not displayed, try refreshing the project references


You can try using a breakpoint and debugging through all the layers to see how it works end to end.


This document is meant to provide information on a NLayers project. You can access the latest source or documentation from:


This article explains some examples of NLayers. You can try executing the example application attached along with the article.

Similar Articles