Created
September 23, 2021 23:08
-
-
Save RMcD/3dfa3bffa88e30b6792ddfced02b7bb6 to your computer and use it in GitHub Desktop.
Only Set Connection String in OnConfiguring for EF Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work. You can check if the connection string is set this way, but it won't actually update it.