It seems to me that the logic of data acquisition, addition and deletion can be somehow generalized, since in fact they all perform the same action only with different data, and there will be quite a lot of tables. Is it possible to come up with something for this example?
public interface IDataRepository { IQueryable<Manufacturer> GetManufacturers(); IQueryable<Product> GetProducts(); void Add(Product product); void Add(Manufacturer manufacturer); void Remove(Product product); void Remove(Manufacturer manufacturer); } public class EFDataRepository : IDataRepository { private readonly WarehouseDbContext _context; public EFDataRepository(WarehouseDbContext context) { _context = context; } public IQueryable<Manufacturer> GetManufacturers() => _context.Manufacturer; public IQueryable<Product> GetProducts() => _context.Products; public void Add(Manufacturer manufacturer) { _context.Manufacturer.Add(manufacturer); _context.SaveChanges(); } public void Add(Product product) { _context.Products.Add(product); _context.SaveChanges(); } public void Remove(Manufacturer manufacturer) { _context.Manufacturer.Remove(manufacturer); _context.SaveChanges(); } public void Remove(Product product) { _context.Products.Remove(product); _context.SaveChanges(); } }