class YourDbContext { private readonly string _connectionString; internal virtual DbSet YourTableClass{ get; set; } //cool, no plublic table access public YourDbContext(string connectionString) : base() { _connectionString = connectionString; } public YourDbContext(DbContextOptions options) //needed for Ef Core reverse .. an so one : base(options) { } //and now.. we pass the connection string in the OnConfigure proc protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. //optionsBuilder.UseNpgsql("ConnectionString needed for Ef Core.. and plese dont use hard coded string ;)"); optionsBuilder.UseNpgsql( _connectionString ); } } }