I have the following generic repository:
public class GenericRepository<TEntity> where TEntity : class {
private EFDbContext context;
private DbSet<TEntity> dbSet;
public GenericRepository(EFDbContext context) {}
public IEnumerable<TEntity> GetAll() {}
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") {}
public TEntity GetByID(int id) {}
public void Insert(TEntity entity) {}
public void Delete(int id) {}
public void Delete(TEntity entity) {}
public void Update(TEntity entity) {}
}
Now I understand how I can use this for my entities, but I don’t understand what to do if an entity needs more than just these methods? Say I have an entity called ‘Tournament’ and I want to get all the groups in that tournament, where would the ‘GetTournamentGroups’ method go?
Should I, instead of using a generic repository, write a basic repository interface which all the entities’ own interfaces inherit from and then just add the additional methods needed for each entity?
Method GetTournamentGroups() seems to belong to the layer above Repository layer:
I’d recommend using IQueryable insteam of IEnumerable in your GenericRepository, though. It would be more flexible if you need to apply filters or sort expressions before you make an actual database query.