I have multiple databases and I need to connect each database when the user selects from dropdown list. I need to create a generic DBContext which connects to multiple database. I started with this but not going anywhere. This is already existing example but I did not understand what is BaseEntity. I took the help from following link:
Connect multiple Databases to .NET core project via Entity Framework Core
public class GenericRepository<TContext, TEntity> : IGenericRepository<TContext, TEntity>
where TContext : DbContext
where TEntity : BaseEntity
{
private readonly TContext _context;
private DbSet<T> entities;
public GenericRepository(TContext context)
{
_context = context;
entities = context.Set<T>();
}
public List<T> GetAll()
{
return entities.AsNoTracking().ToList();
}
}