Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active August 2, 2020 08:17
Show Gist options
  • Select an option

  • Save PradeepLoganathan/e0b9f61c2ceb3392ee5fcf855990cfe5 to your computer and use it in GitHub Desktop.

Select an option

Save PradeepLoganathan/e0b9f61c2ceb3392ee5fcf855990cfe5 to your computer and use it in GitHub Desktop.
public abstract class GenericRepository<T> : IGenericRepository<T> where T : class
{
protected readonly BookStoreDbContext _context;
public GenericRepository(BookStoreDbContext context)
{
_context = context;
}
public async Task<T> Get(int id)
{
return await _context.Set<T>().FindAsync(id);
}
public async Task<IEnumerable<T>> GetAll()
{
return await _context.Set<T>().ToListAsync();
}
public async Task Add(T entity)
{
await _context.Set<T>().AddAsync(entity);
}
public void Delete(T entity)
{
_context.Set<T>().Remove(entity);
}
public void Update(T entity)
{
_context.Set<T>().Update(entity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment