Skip to content

Commit 13530dc

Browse files
committed
Use NpgsqlConnection when checking if database exists.
The NpgsqlRelationalConnection gets an implicit reference to the DbContext from the original connection (through Dependencies). That could tamper with the original DbContext's ServiceProvider when adding a connection to completly different pool. Also, the test only wants a connection to the database which NpgsqlConnection could provide. CreateAdminConnection suffers from the same problem. That together with this may be the root of the problem of #3560.
1 parent fe4269f commit 13530dc

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/EFCore.PG/Storage/Internal/INpgsqlRelationalConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public interface INpgsqlRelationalConnection : IRelationalConnection
3232
/// any release. You should only use it directly in your code with extreme caution and knowing that
3333
/// doing so can result in application failures when updating to a new Entity Framework Core release.
3434
/// </summary>
35-
ValueTask<INpgsqlRelationalConnection> CloneWith(string connectionString, bool async, CancellationToken cancellationToken = default);
35+
ValueTask<NpgsqlConnection> CloneWith(string connectionString, bool async, CancellationToken cancellationToken = default);
3636
}

src/EFCore.PG/Storage/Internal/NpgsqlRelationalConnection.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public override Transaction? CurrentAmbientTransaction
232232
/// any release. You should only use it directly in your code with extreme caution and knowing that
233233
/// doing so can result in application failures when updating to a new Entity Framework Core release.
234234
/// </summary>
235-
public virtual async ValueTask<INpgsqlRelationalConnection> CloneWith(
235+
public virtual async ValueTask<NpgsqlConnection> CloneWith(
236236
string connectionString,
237237
bool async,
238238
CancellationToken cancellationToken = default)
@@ -241,13 +241,6 @@ public virtual async ValueTask<INpgsqlRelationalConnection> CloneWith(
241241
? await DbConnection.CloneWithAsync(connectionString, cancellationToken).ConfigureAwait(false)
242242
: DbConnection.CloneWith(connectionString);
243243

244-
var relationalOptions = RelationalOptionsExtension.Extract(Dependencies.ContextOptions)
245-
.WithConnectionString(null)
246-
.WithConnection(clonedDbConnection);
247-
248-
var optionsBuilder = new DbContextOptionsBuilder();
249-
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(relationalOptions);
250-
251-
return new NpgsqlRelationalConnection(Dependencies with { ContextOptions = optionsBuilder.Options }, dataSource: null);
244+
return clonedDbConnection;
252245
}
253246
}

0 commit comments

Comments
 (0)