Entity Framework Repository Pattern Demo Application

You can download the source code here.

Repository Pattern
-> A data access pattern.
-> Separates persistence responsibility from business classes.
-> Enables
1) Single Responsibility Principle
2) Separation of Concerns
3) Testability
-> Separates interfaces for each entity in application.
e.g CustomerRepository, OrderRepository

Setup projects in Visual Studio

  1. Create a new solution in Visual Studio.
  2. Add a library project for Entity or model classes. Here I created a library project Codify.Entity.
  3. Add a library project for data access related classes. In demo application Codify.DataAccess refers to this.
  4. Add a console application to write the test code.
  5. Below are the projects in the solutions

1)  Codify.DataAccess
2)  Codify.Entity
3)  Codify.TestConsole

The demo app is a simpl Employee – Order management application. The application helps to create Employees, Products and creates orders for the employees using products created. Below is the DB diagram of the tables.

Now add a BaseEntity class to Codify.Entity project. The BaseEntity contains common properties like CreatedDate, CreatedBy etc. which are part of all tables.

Add a class file for Employee entity.

Add a class file for Product entity

Add a class file for Order entity

Add a class file for Order Details Entity.

Below is the class diagram for models or entities.

The project structure is as shown below.

One comment on “Entity Framework Repository Pattern Demo Application

Leave a Reply

Your email address will not be published. Required fields are marked *