Friday, 1 February 2019

Repository pattern in C#

Repository pattern:


Domain entities,
Data access logic(CURD operations using entity framework or ADO.net ..) and
Business logic(Employee class: our methods like getEmployeeList, InsertEmp,deleteEmp..)
talk to each other using interfaces(IEmployee interface).

It hides the details of data access from the business logic.


Example:
Repository folder: 
   1. Take IEmployee interface
   interface IEmployee 
   {
     void InsertEmp(Employee emp);
     IEnumerable<Employee> getEmployee();
     void UpdateEmp(Employee emp);
     void DeleteEmp(int empId);
   }

   2. Take EmployeeRepository class
   public class EmployeeRepository: IEmployee
   {
     private EmployeeContext _context
     public EmployeeRepository(EmployeeContext context){
_context = context;
}
     //Need to Implement IEmployee method implementations

   }