--

If you want to implement the same follow these steps.

Modify the GetRepository<TEntity> method in your Unit of Work class to return an instance of IStudentRepository when TEntity is Student:

public class UnitOfWork : IUnitOfWork

{

private readonly DbContext _context;

public IRepository<TEntity> GetRepository<TEntity>() where TEntity : class

{

if (typeof(TEntity) == typeof(Student))

{

return new StudentRepository(_context) as IRepository<TEntity>;

}

else

{

return new Repository<TEntity>(_context);

}

}

}

With these changes, you can now access the GetByRollNo() method specifically for the Student entity through an instance of IStudentRepository.

Other methods defined in the IRepository<TEntity> interface will still be accessible through the same instance.

Hope these changes will help you achieve your requirement.

--

--

DotNet Full Stack Dev
DotNet Full Stack Dev

Written by DotNet Full Stack Dev

Join me to master .NET Full Stack Development & boost your skills by 1% daily with insights, examples, and techniques! https://dotnet-fullstack-dev.blogspot.com

Responses (1)