Skip to content

Clear predicate when translating full-text table-valued functions - #39774

Open
SkyDevLab wants to merge 1 commit into
dotnet:mainfrom
SkyDevLab:fix/39686-freetexttable-query-filter
Open

SkyDevLab wants to merge 1 commit into
dotnet:mainfrom
SkyDevLab:fix/39686-freetexttable-query-filter

Conversation

@SkyDevLab

Copy link
Copy Markdown
Contributor

Fixes #39686

Description

When querying FreeTextTable or ContainsTable on a DbSet where TEntity has a global query filter defined (e.g. p => !p.IsDeleted), SqlServerQueryableMethodTranslatingExpressionVisitor.TranslateFullTextTableFunction replaced the table in select.Tables with the table-valued function (FREETEXTTABLE / CONTAINSTABLE), but left any existing select.Predicate intact on the SelectExpression.

Because the original entity table alias (e.g. [p]) is no longer in the FROM clause, the lingering query filter in select.Predicate generated an undeclared alias reference in the WHERE clause:
sql SELECT [p0].[KEY] AS [Key], [p0].[RANK] AS [Rank] FROM FREETEXTTABLE([Posts], *, @p) AS [p0] WHERE [p].[IsDeleted] = 0 -- undeclared alias [p]
This resulted in SQL Server error 4104 (The multi-part identifier p.IsDeleted could not be bound.).

Fix

  • Added [EntityFrameworkInternal] public void ClearPredicate() to SelectExpression allowing clearing the predicate on a mutable SelectExpression.
  • Called select.ClearPredicate() in SqlServerQueryableMethodTranslatingExpressionVisitor.TranslateFullTextTableFunction after setting the TVF tables.
  • Added unit tests in EFCore.SqlServer.Tests covering both FreeTextTable and ContainsTable with global query filters.

@SkyDevLab
SkyDevLab requested a review from a team as a code owner November 23, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant