I need to implement a generic repository (reuseable .dll) for applying operations ( e.g update, insert, delete, search ) keeping the fact we can make complex queries from database containing multiple joins and complexity.
I am doing in this way
public class GenericRepository<TEntity> where TEntity : class
{
//internal SchoolContext context; which context I need to use to behav as generic(.dll)
internal DbSet<TEntity> dbSet;
public GenericRepository(SchoolContext context) //that won't be this context
{
this.context = context;
this.dbSet = context.Set<TEntity>();
}
.... public virtual void Insert(TEntity entity){..}
.... public virtual void Delete(TEntity entityToDelete){..}
.... public virtual void Update(TEntity entityToUpdate){..}
}
So, which context, somehow to achieve the same working of DBContexts (i.e to interact with DB from objects using LINQ)?
Secondly, I am using some specific classes ( in case when this generic repository don't fulfills my operational requirement ) like some huge complex query. like
class StudentRepository : GenericRepository
{
}
class PersonRepository : GenericRepository
{
}
... Is this way is right or some other good implementation is available ?
Regards Usman