Skip to content

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

Open

Description

@cmdRus

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

Activity

  1. roji commented on Apr 3, 2025

    @roji
    Member

    @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.

  2. cmdRus commented on Apr 3, 2025

    @cmdRus
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions