Skip to content

FreeTextTable: query filter of the source entity is applied with an undeclared alias #39686

Description

@duguankui

Bug description

When the entity passed to FreeTextTable has a global query filter, the filter is appended to the TVF query referencing a table alias that is never declared, so SQL Server rejects the query.

Your code

using Microsoft.EntityFrameworkCore;

using var ctx = new BlogContext();
var hits = ctx.Posts.FreeTextTable<Post, int>("search");
Console.WriteLine(hits.ToQueryString());

public class Post { public int Id { get; set; } public string Text { get; set; } = ""; public bool IsDeleted { get; set; } }

public class BlogContext : DbContext
{
    public DbSet<Post> Posts => Set<Post>();
    protected override void OnConfiguring(DbContextOptionsBuilder o) => o.UseSqlServer("Server=.;Database=x;Trusted_Connection=True");
    protected override void OnModelCreating(ModelBuilder b) => b.Entity<Post>().HasQueryFilter(p => !p.IsDeleted);
}

Generated SQL:

DECLARE @p nvarchar(4000) = N'search';

SELECT [f].[KEY] AS [Key], [f].[RANK] AS [Rank]
FROM FREETEXTTABLE([Posts], *, @p) AS [f]
WHERE [p].[IsDeleted] = CAST(0 AS bit)

Executing it fails with The multi-part identifier "p.IsDeleted" could not be bound. Joining the result back to ctx.Posts (the documented pattern) produces the same dangling WHERE after the join.

Expected

Either the filter is not applied to the TVF itself (its rows are keys and ranks, not entities; the filter applies when joining back to the entity set), or it is applied through a correctly aliased join to the table. Today there is no workaround short of IgnoreQueryFilters() on the whole query, which also removes the filter from the join — not acceptable for multi-tenant filters.

Versions

  • Microsoft.EntityFrameworkCore.SqlServer 11.0.0
  • .NET 11.0.100, Windows 11
  • SQL Server 2025 (17.0.5065.9)

Activity

  1. self-assigned this
    on Nov 18, 2026
  2. added theissue type on Nov 18, 2026
  3. added this to the 12.0.0 milestone on Nov 18, 2026
  4. cincuranet commented on Nov 18, 2026

    @cincuranet
    Contributor

    As a workaround you can use named query filters and ignore only the one for IsDeleted. Nonetheless it's a bug and will be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions