Skip to content

Commit c647b62

Browse files
committed
Switched to DataSourceConfigurationPlugin - resolves #51
1 parent cb50f16 commit c647b62

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

src/Pgvector.EntityFrameworkCore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.0 (unreleased)
2+
3+
- Dropped support for Npgsql.EntityFrameworkCore.PostgreSQL < 9
4+
15
## 0.2.2 (2025-03-26)
26

37
- Added support for scaffolding

src/Pgvector.EntityFrameworkCore/Pgvector.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
2323
<None Include="build\**\*" Pack="true" PackagePath="build" />
2424
<ProjectReference Include="..\Pgvector\Pgvector.csproj" />
25-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
25+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
2626
</ItemGroup>
2727

2828
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Npgsql;
2+
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
3+
4+
namespace Pgvector.EntityFrameworkCore;
5+
6+
public class VectorDataSourceConfigurationPlugin : INpgsqlDataSourceConfigurationPlugin
7+
{
8+
public void Configure(NpgsqlDataSourceBuilder npgsqlDataSourceBuilder)
9+
=> npgsqlDataSourceBuilder.UseVector();
10+
}

src/Pgvector.EntityFrameworkCore/VectorDbContextOptionsBuilderExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Microsoft.EntityFrameworkCore.Infrastructure;
2-
using Npgsql;
32
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
43
using Pgvector.EntityFrameworkCore;
54
using Pgvector.Npgsql;
@@ -10,11 +9,6 @@ public static class VectorDbContextOptionsBuilderExtensions
109
{
1110
public static NpgsqlDbContextOptionsBuilder UseVector(this NpgsqlDbContextOptionsBuilder optionsBuilder)
1211
{
13-
// not ideal, but how Npgsql.EntityFrameworkCore.PostgreSQL does it
14-
#pragma warning disable CS0618
15-
NpgsqlConnection.GlobalTypeMapper.UseVector();
16-
#pragma warning restore CS0618
17-
1812
var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
1913

2014
var extension = coreOptionsBuilder.Options.FindExtension<VectorDbContextOptionsExtension>()

src/Pgvector.EntityFrameworkCore/VectorDbContextOptionsExtension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.EntityFrameworkCore.Query;
33
using Microsoft.EntityFrameworkCore.Storage;
44
using Microsoft.Extensions.DependencyInjection;
5+
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
56

67
namespace Pgvector.EntityFrameworkCore;
78

@@ -13,7 +14,8 @@ public class VectorDbContextOptionsExtension : IDbContextOptionsExtension
1314

1415
public void ApplyServices(IServiceCollection services)
1516
{
16-
new EntityFrameworkRelationalServicesBuilder(services)
17+
new EntityFrameworkNpgsqlServicesBuilder(services)
18+
.TryAdd<INpgsqlDataSourceConfigurationPlugin, VectorDataSourceConfigurationPlugin>()
1719
.TryAdd<IMethodCallTranslatorPlugin, VectorDbFunctionsTranslatorPlugin>();
1820

1921
services.AddSingleton<IRelationalTypeMappingSourcePlugin, VectorTypeMappingSourcePlugin>();

0 commit comments

Comments
 (0)