Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<EFCoreVersion>[9.0.0-rc.2.24474.1]</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-rc.2.24473.5</MicrosoftExtensionsVersion>
<NpgsqlVersion>9.0.0-preview.1-ci.20241025T100626</NpgsqlVersion>
<NpgsqlVersion>9.0.0-preview.1-ci.20241028T080028</NpgsqlVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 11 additions & 1 deletion src/EFCore.PG/Storage/Internal/INpgsqlRelationalConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
using System.Data.Common;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -8,6 +10,14 @@
/// </summary>
public interface INpgsqlRelationalConnection : IRelationalConnection
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
DbDataSource? DataSource { get; }

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
21 changes: 19 additions & 2 deletions src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,15 @@ private static bool IsDoesNotExist(PostgresException exception)
/// </summary>
public override void Delete()
{
ClearAllPools();
switch (_connection.DataSource)
{
case NpgsqlDataSource dataSource:
dataSource.Clear();
break;
case null:
ClearAllPools();
break;
}

using (var masterConnection = _connection.CreateAdminConnection())
{
Expand All @@ -290,7 +298,16 @@ public override void Delete()
/// </summary>
public override async Task DeleteAsync(CancellationToken cancellationToken = default)
{
ClearAllPools();
switch (_connection.DataSource)
{
case NpgsqlDataSource dataSource:
// TODO: Do this asynchronously once https://github.com/npgsql/npgsql/issues/4499 is done
dataSource.Clear();
break;
case null:
ClearAllPools();
break;
}

var masterConnection = _connection.CreateAdminConnection();
await using (masterConnection)
Expand Down
26 changes: 16 additions & 10 deletions src/EFCore.PG/Storage/Internal/NpgsqlRelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public class NpgsqlRelationalConnection : RelationalConnection, INpgsqlRelationa
private readonly ProvidePasswordCallback? _providePasswordCallback;
#pragma warning restore CS0618

private DbDataSource? _dataSource;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public DbDataSource? DataSource { get; private set; }

/// <summary>
/// Indicates whether the store connection supports ambient transactions
Expand Down Expand Up @@ -58,7 +64,7 @@ protected NpgsqlRelationalConnection(RelationalConnectionDependencies dependenci
{
if (dataSource is not null)
{
_dataSource = dataSource;
DataSource = dataSource;

#if DEBUG
// We validate in NpgsqlOptionsExtensions.Validate that DataSource and these callbacks aren't specified together
Expand Down Expand Up @@ -92,9 +98,9 @@ protected NpgsqlRelationalConnection(RelationalConnectionDependencies dependenci
/// </summary>
protected override DbConnection CreateDbConnection()
{
if (_dataSource is not null)
if (DataSource is not null)
{
return _dataSource.CreateConnection();
return DataSource.CreateConnection();
}

var conn = new NpgsqlConnection(ConnectionString);
Expand Down Expand Up @@ -132,12 +138,12 @@ protected override DbConnection CreateDbConnection()
// TODO: Remove after DbDataSource support is added to EF Core (https://github.com/dotnet/efcore/issues/28266)
public override string? ConnectionString
{
get => _dataSource is null ? base.ConnectionString : _dataSource.ConnectionString;
get => DataSource is null ? base.ConnectionString : DataSource.ConnectionString;
set
{
base.ConnectionString = value;

_dataSource = null;
DataSource = null;
}
}

Expand All @@ -155,7 +161,7 @@ public override string? ConnectionString
{
base.DbConnection = value;

_dataSource = null;
DataSource = null;
}
}

Expand All @@ -167,12 +173,12 @@ public override string? ConnectionString
/// </summary>
public virtual DbDataSource? DbDataSource
{
get => _dataSource;
get => DataSource;
set
{
DbConnection = null;
ConnectionString = null;
_dataSource = value;
DataSource = value;
}
}

Expand All @@ -196,7 +202,7 @@ public virtual INpgsqlRelationalConnection CreateAdminConnection()
Multiplexing = false
}.ToString();

var adminNpgsqlOptions = _dataSource is not null
var adminNpgsqlOptions = DataSource is not null
? npgsqlOptions.WithConnection(((NpgsqlConnection)CreateDbConnection()).CloneWith(adminConnectionString))
: npgsqlOptions.Connection is not null
? npgsqlOptions.WithConnection(DbConnection.CloneWith(adminConnectionString))
Expand Down