using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
public static void Main()
public interface IRepository<T> where T : class
public List<T> GetAllEntities();
public T Update(T entity);
public abstract class BaseRepository<TEntity, TContext> : IRepository<TEntity>
where TContext : DbContext
private readonly TContext _dbContext;
protected BaseRepository(TContext dbContext)
public List<TEntity> GetAllEntities()
return _dbContext.Set<TEntity>().ToList();
public TEntity Get(int id)
return _dbContext.Set<TEntity>().Find(id);
public TEntity Add(TEntity entity)
_dbContext.Set<TEntity>().Add(entity);
_dbContext.SaveChanges();
public TEntity Update(TEntity entity)
throw new NotImplementedException();
public TEntity Delete(int id)
throw new NotImplementedException();