Skip to content

Missing EF Core 10 documentation #61

@dotnetKyle

Description

@dotnetKyle

When configuring the database to use Vector, and you are on EF Core 10, you can have a problem with the instructions if you are using a custom NpgsqlDataSourceBuilder for any reason.

For example, if you are following the current EF Core 10 README instructions that say this:

// Configure the connection
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseNpgsql("connString", o => o.UseVector());
}

and if you configure your database slightly differently in this way:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    NpgsqlDataSourceBuilder dataSourceBuilder = new(connectionString);
    NpgSqlDataSource dataSource = dataSourceBuilder.Build();

    optionsBuilder.UseNpgsql(dataSource, o => o.UseVector());
}

Then you are missing this bit of configuration: dataSourceBuilder.UseVector(); before calling dataSource = dataSourceBuilder.Build();. If you leave this out, during runtime, saving a Vector will throw this exception: System.InvalidCastException: Writing values of 'Pgvector.Vector' is not supported. As a new user, this was confusing for me. Luckily, I came across @MoondanceZ's comment but I missed the critical part of his changes the first time I read it.

I recommend doing 1 of 2 of these options:

  1. Do nothing and let this Issue serve as documentation
  2. Explicitly change the documentation to use a NpgsqlDataSourceBuilder this use case is covered, if the user uses a string connection string instead, then it will just work.

In case you want to do option 2, I will open a PR to modify the docs, if not, you can just close the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions