Skip to content

Full Text Search method "Matches" fails when not using a string query #3041

Closed

Description

@balloman

I have a query where I'm calling

var tsQuery = new NpgsqlTsQueryLexeme("firs", Weight.None, true);
var results = await context.Record.Where(r => r.SearchVector.Matches(tsQuery)).ToArrayAsync;

This query always fails with the error:
Expression '@__tsQuery_0' in the SQL tree does not have a type mapping assigned

Is this intended behavior, and I'm doing something wrong, or a bug?

Version 8.0.0

Activity

  1. roji commented on Oct 20, 2026

    @roji
    Member

    AI Triage

    The below is an AI-generated analysis and may contain inaccuracies.

    Confirmed a PostgreSQL-provider bug: the parameter's declared CLR type matters. var tsQuery = new NpgsqlTsQueryLexeme(...) produces a parameter typed as NpgsqlTsQueryLexeme, but the provider only registers a mapping for the base NpgsqlTsQuery type. Consequently, .Matches(tsQuery) fails during query translation, before any connection to PostgreSQL is needed.

    The minimal repro below fails with the reported missing-type-mapping exception on provider 7.0.18, 8.0.0, 8.0.11, and 10.0.3. The current main branch also lacks mappings for the derived tsquery types. This is therefore not a regression introduced in 8.0; no earlier working version was identified.

    A verified workaround on 8.0.0 and 10.0.3 is to declare the variable as the base type:

    NpgsqlTsQuery tsQuery = new NpgsqlTsQueryLexeme("firs", NpgsqlTsQueryLexeme.Weight.None, true);

    This is provider-specific: NpgsqlTsQuery, NpgsqlTsVector, and their full-text operators are PostgreSQL-specific APIs, so switching this repro to another provider would not test the same behavior.

    Issue #886 previously identified the missing derived-type mappings as a separate problem alongside an empty-query driver failure. It is related, but the driver roundtrip problem is not needed to reproduce this issue. No matching existing PR or duplicate in the EF Core repository was found. The similarly named dotnet/efcore#27146 concerns text-search configuration, not CLR type mapping.

    minimal repro

    Reference Npgsql.EntityFrameworkCore.PostgreSQL version 8.0.0 (also reproduced with the other versions above). No database is required because ToQueryString() triggers the failure.

    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Logging;
    using NpgsqlTypes;
    
    using var context = new TestContext();
    var tsQuery = new NpgsqlTsQueryLexeme("firs", NpgsqlTsQueryLexeme.Weight.None, true);
    Console.WriteLine(context.Record.Where(r => r.SearchVector.Matches(tsQuery)).ToQueryString());
    
    public class TestContext : DbContext
    {
        public DbSet<Record> Record => Set<Record>();
    
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            => optionsBuilder
                .UseNpgsql("Host=localhost;Database=repro")
                .LogTo(Console.WriteLine, LogLevel.Information)
                .EnableSensitiveDataLogging();
    }
    
    public class Record
    {
        public int Id { get; set; }
        public NpgsqlTsVector SearchVector { get; set; } = null!;
    }
  2. added theissue type on Oct 20, 2026
  3. self-assigned this
    on Oct 20, 2026
  4. added this to the 10.0.4 milestone on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions