Skip to content

Commit 228f3d4

Browse files
committed
Switched to DataSourceConfigurationPlugin
1 parent 123eeaa commit 228f3d4

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

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.0" />
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ public static class VectorDbContextOptionsBuilderExtensions
1010
{
1111
public static NpgsqlDbContextOptionsBuilder UseVector(this NpgsqlDbContextOptionsBuilder optionsBuilder)
1212
{
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-
1813
var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
1914

2015
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)