Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I am new to mvc and trying to implement small application using repository pattern. I have different layer.
1- MVC Application layer
2-Service layer
3-Repository layer
4-Database layer- I am using EF Datafirst

Now I am working on employee creation. This is how my code is.

In Repository Layer
public class Repository :IRepository where TEntity : class
{
internal DbSet dbSet;
private HREntities _context;


public IQueryable GetAll()
{
return dbSet.AsQueryable();
}
......
}

In Service layer I am calling this Repository layer

public class EmployeeService:IEmployee
{
private IRepository _employeeRepository;

public EmployeeService(IRepository employeeRepository)
{
this._employeeRepository = employeeRepository;
}

public EmployeeService()
: this(new Repository())
{

}
......
}

I am fine still here now how can I use this service class in my controller. Please help me .
Posted
Comments
Nathan Minier 22-Jan-15 7:39am    
You know, DbContext (and it's children, such as your HREntities), already implement the Repository pattern. There's no real need to re-invent the wheel unless you're doing something that will potentially be using many different data sources and must enforce specific interface requirements.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900