Skip to content

Commit

Permalink
Add [NotParameterized] for language term in FreeText/Contains
Browse files Browse the repository at this point in the history
Resolves #13315
  • Loading branch information
thomaslevesque authored and smitpatel committed Mar 17, 2020
1 parent 6f19f3d commit eeb9cf9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.SqlServer.Internal;
using Microsoft.EntityFrameworkCore.Query;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
Expand Down Expand Up @@ -33,7 +32,7 @@ public static bool FreeText(
[CanBeNull] this DbFunctions _,
[NotNull] string propertyReference,
[NotNull] string freeText,
int languageTerm)
[NotParameterized] int languageTerm)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FreeText)));

/// <summary>
Expand Down Expand Up @@ -71,7 +70,7 @@ public static bool Contains(
[CanBeNull] this DbFunctions _,
[NotNull] string propertyReference,
[NotNull] string searchCondition,
int languageTerm)
[NotParameterized] int languageTerm)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains)));

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ FROM [Employees] AS [e]
WHERE FREETEXT([e].[Title], N'President', LANGUAGE 1033)");
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void FreeText_with_non_literal_language_term()
{
int language = 1033;
using var context = CreateContext();
var result = context.Employees.SingleOrDefault(c => EF.Functions.FreeText(c.Title, "President", language));

Assert.Equal(2u, result.EmployeeID);

AssertSql(
@"SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
WHERE FREETEXT([e].[Title], N'President', LANGUAGE 1033)");
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void FreeText_with_multiple_words_and_language_term()
Expand Down Expand Up @@ -309,6 +325,22 @@ FROM [Employees] AS [e]
WHERE CONTAINS([e].[Title], N'President', LANGUAGE 1033)");
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void Contains_with_non_literal_language_term()
{
int language = 1033;
using var context = CreateContext();
var result = context.Employees.SingleOrDefault(c => EF.Functions.Contains(c.Title, "President", language));

Assert.Equal(2u, result.EmployeeID);

AssertSql(
@"SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
WHERE CONTAINS([e].[Title], N'President', LANGUAGE 1033)");
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public async Task Contains_with_logical_operator()
Expand Down

0 comments on commit eeb9cf9

Please sign in to comment.