Skip to content

Instantly share code, notes, and snippets.

@RMcD
Created September 23, 2021 23:08
Show Gist options
  • Save RMcD/3dfa3bffa88e30b6792ddfced02b7bb6 to your computer and use it in GitHub Desktop.
Save RMcD/3dfa3bffa88e30b6792ddfced02b7bb6 to your computer and use it in GitHub Desktop.
Only Set Connection String in OnConfiguring for EF Core
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//Generically set the connection string regardless of .UseSqlServer/.UsePgSQL/etc.
var relationalOptions = optionsBuilder.Options.FindExtension<RelationalOptionsExtension>();
optionsBuilder.Options.WithExtension(relationalOptions.WithConnectionString(_connectionString));
}
@RMcD
Copy link
Author

RMcD commented Sep 28, 2021

This doesn't work. You can check if the connection string is set this way, but it won't actually update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment