ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 281.5k

How to implement repository pattern in asp.net core 2.1

Jan 16 2019 8:20 PM

Problem

How to implement repository pattern in asp.net core 2.1 visual studio 2017 with SQL server 2012 ?

i work on project work on repository pattern but i cannot implement it

model Employee

  1. public class Employee   
  2. {   
  3. public int EmployeeId { getset; }   
  4. public int BranchCode { getset; }   
  5. public string EmployeeName { getset; }   
  6. public int EmployeeAge { getset; }   
  7. }   
  8. Repository public class RepositoryTab : IrepositoryTab where T : class   
  9. {   
  10. protected TabDbContext db { getset; }   
  11. private DbSet dbSet;  
  12.  public RepositoryTab(TabDbContext Tabdb)   
  13. {              
  14.  db = Tabdb;              
  15.  dbSet = db.Set();   
  16. }   
  17. public IEnumerable GetAll()   
  18. {  
  19.  return dbSet.ToList();  
  20.  }   
  21. }   
  22. public interface IrepositoryTab where T : class { IEnumerable GetAll();        
  23. T GetById(object Id);  
  24.  }  
 1- How to define repository on controller Employee to call function GetAll on constructor?

meaning how to define repository on constructor of controller

3- suppose i have compost key how to use getbyid suppose i have (Employeid,branchcode) as compost key ?

are compost key define as fluent api or annotation or what ?

please can you help me and give me details if possible

can any one answer me of this question please ?


Answers (1)