Skip to content

Cannot convert annotation of "TsVectorProperties" to snake case for NpgsqlTsVector #3515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmdRus opened this issue Apr 3, 2025 · 2 comments

Comments

@cmdRus
Copy link

cmdRus commented Apr 3, 2025

Hello, We are facing an issue where we are unable to convert the SearchVector annotation for NpgsqlTsVector to snake case.
Image
We have enabled the default conversion of all tables and columns to lowercase (UseSnakeCaseNamingConvention), but when building the migration, the annotation is not converted to lowercase, so we had to explicitly specify uppercase for the SearchVector column so that the annotation references an existing column.
Image
Image
Can you suggest how to resolve this issue and convert everything to snake case?

ps
explicitly specifying a lowercase column name for a column via attribute or fluent api does not help

Image

@roji
Copy link
Member

roji commented Apr 3, 2025

@cmdRus please don't post screenshots when posting issues - a minimal, runnable console program (in actual code) which reproduces the error is what's needed when posting a bug report.

As an aside, having 11 colleagues thumbs-up an issue creates the false impression that many users are hitting this.

@cmdRus
Copy link
Author

cmdRus commented Apr 3, 2025

@roji I am attaching an example that reproduces the error. I apologize for the initially incorrectly formulated issue. The problem occurs when renaming a column, not when creating it
TestTsVector.zip

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using NpgsqlTypes;
using System.ComponentModel.DataAnnotations.Schema;

[Table("search_entities")]
public class SearchEntity
{
    [Column("id")]
    public int Id { get; set; }

    [Column("search_string")]
    public string SearchString { get; set; } = null!;

    [Column("search_vector")]
    public NpgsqlTsVector SearchVector { get; set; } = null!;
}

public class DatabaseContext : DbContext
{
    public DbSet<SearchEntity> SearchEntities { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=test_ts_vector_local;Username=postgres;Password=postgres");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<SearchEntity>(entity =>
        {
            entity.HasGeneratedTsVectorColumn(p => p.SearchVector, "russian", p => p.SearchString);
            entity.HasIndex(p => p.SearchVector).HasMethod("GIN");
        });
    }
}


class Programm
{
    static void Main(string[] args)
    {
        using var context = new DatabaseContext();
        var count = context.SearchEntities.Count();
        Console.WriteLine(count);
        Console.ReadLine();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants