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
1- How to define repository on controller Employee to call function GetAll on constructor?
meaning how to define repository on constructor of controller
2- what i write on startup to define these modules and connection ?
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 ?
What I have tried:
model Employee
public class Employee
{
public int EmployeeId { get; set; }
public int BranchCode { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
Repository public class RepositoryTab<T> : IrepositoryTab<T> where T : class
{
protected TabDbContext db { get; set; }
private DbSet<T> dbSet;
public RepositoryTab(TabDbContext Tabdb)
{
db = Tabdb;
dbSet = db.Set<T>();
}
public IEnumerable<T> GetAll()
{
return dbSet.ToList();
}
}
public interface IrepositoryTab<T> where T : class { IEnumerable<T> GetAll();
T GetById(object Id);
}