using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace BelegeingangDatabase.Repositories { public class GenericRepository : IGenericRepository where T : class { protected readonly BelegeingangContext _context; private readonly DbSet _dbSet; public GenericRepository(BelegeingangContext context) { _context = context; _dbSet = _context.Set(); } public virtual async Task> GetAllAsync() { return await _dbSet.ToListAsync(); } public virtual async Task> FindAsync(Expression> predicate) { return await _dbSet.Where(predicate).ToListAsync(); } public virtual async Task GetByIdAsync(int id) { return await _dbSet.FindAsync(id); } public virtual async Task AddAsync(T entity) { await _dbSet.AddAsync(entity); } public virtual void Update(T entity) { _dbSet.Update(entity); } public virtual void Remove(T entity) { _dbSet.Remove(entity); } } }