Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ public void SetTables(IReadOnlyList<TableExpressionBase> tables)
_tables.AddRange(tables);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public void ClearPredicate()
{
Check.DebugAssert(IsMutable, "Attempt to mutate an immutable SelectExpression");
Predicate = null;
}

/// <summary>
/// Applies a given set of tags.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ private Expression TranslateFullTextTableFunction(

#pragma warning disable EF1001 // Internal EF Core API usage.
select.SetTables([fullTextTableFunction]);
select.ClearPredicate();
#pragma warning restore EF1001 // Internal EF Core API usage.

var keyProjectionMember = new ProjectionMember().Append(resultType.GetProperty(nameof(FullTextSearchResult<int>.Key))!);
Expand Down
47 changes: 47 additions & 0 deletions test/EFCore.SqlServer.Tests/Query/FullTextTableQueryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Query;

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

private class BlogContext : DbContext
{
public DbSet<Post> Posts => Set<Post>();

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer("Server=localhost;Database=Test;Trusted_Connection=True;TrustServerCertificate=True");

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Post>().HasQueryFilter(p => !p.IsDeleted);
}

[Fact]
public void FreeTextTable_with_query_filter_does_not_generate_filter_with_undeclared_alias()
{
using var ctx = new BlogContext();
var hits = ctx.Posts.FreeTextTable<Post, int>("search");
var sql = hits.ToQueryString();

Assert.Contains("FREETEXTTABLE([Posts], *, @p)", sql);
Assert.DoesNotContain("WHERE", sql);
}

[Fact]
public void ContainsTable_with_query_filter_does_not_generate_filter_with_undeclared_alias()
{
using var ctx = new BlogContext();
var hits = ctx.Posts.ContainsTable<Post, int>("search");
var sql = hits.ToQueryString();

Assert.Contains("CONTAINSTABLE([Posts], *, @p)", sql);
Assert.DoesNotContain("WHERE", sql);
}
}
Loading