Articles → .NET DESIGN PATTERN → Repository Pattern in C#

Repository Pattern in C#






What is a repository pattern?


















public interface IRepository <T> {
  void Add(T entity);
  void Update(T entity);
  void Delete(T entity);
  T GetById(int Id);
  IEnumerable <T> GetAll();
}

public class Employee {
  public int Id {
    get;
    set;
  }
  public string EmployeeName {
    get;
    set;
  }
}

public class EmployeeRepository: IRepository <Employee> {
  //  Declare DbContext
  public void Add(Employee entity) {
    //  Write a logic for adding an employee
  }

  public void Delete(Employee entity) {
    //  Write a logic for delete an employee
  }

  public IEnumerable <Employee> GetAll() {
    //  Write a logic to get the list of all employees
    throw new NotImplementedException();
  }

  public Employee GetById(int Id) {
    //  Write a logic to get the employee details from Id
    throw new NotImplementedException();
  }

  public void Update(Employee entity) {
    //  Write a logic for update an employee
    throw new NotImplementedException();
  }
}



Posted By  -  Karan Gupta
 
Posted On  -  Sunday, December 27, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250