Skip to content

Commit 56a682a

Browse files
authored
Rename JsonExists to JsonPathExists (#37732)
Part of #31136
1 parent 6f19809 commit 56a682a

File tree

8 files changed

+33
-34
lines changed

8 files changed

+33
-34
lines changed

src/EFCore.Relational/Extensions/RelationalDbFunctionsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public static T Greatest<T>(this DbFunctions _, [NotParameterized] params T[] va
5656
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
5757
/// <param name="json">The JSON value to check.</param>
5858
/// <param name="path">The JSON path to look for.</param>
59-
public static bool JsonExists(this DbFunctions _, object json, string path)
60-
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonExists)));
59+
public static bool JsonPathExists(this DbFunctions _, object json, string path)
60+
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonPathExists)));
6161
}

src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,6 @@ private void ApplySetOperation(
20722072
SelectExpression select2,
20732073
bool distinct)
20742074
{
2075-
// TODO: Introduce clone method? See issue#24460
20762075
var select1 = new SelectExpression(
20772076
alias: null, tables: _tables.ToList(), groupBy: _groupBy.ToList(), projections: [], orderings: _orderings.ToList(),
20782077
annotations: Annotations, sqlAliasManager: _sqlAliasManager)

src/EFCore.Relational/Query/SqlNullabilityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ protected virtual bool TryMakeNonNullable(
19571957
var rewrittenCollectionTable = UpdateParameterCollection(collectionTable, rewrittenParameter);
19581958

19591959
// We clone the select expression since Update below doesn't create a pure copy, mutating the original as well (because of
1960-
// TableReferenceExpression). TODO: Remove this after #31327.
1960+
// TableReferenceExpression). TODO: Remove this after SelectExpression becomes fully mutable (#32927).
19611961
#pragma warning disable EF1001
19621962
rewrittenSelectExpression = selectExpression.Clone();
19631963
#pragma warning restore EF1001

src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
315315
typeof(int));
316316
}
317317

318-
// We translate EF.Functions.JsonExists here and not in a method translator since we need to support JsonExists over
318+
// We translate EF.Functions.JsonPathExists here and not in a method translator since we need to support JsonPathExists over
319319
// complex and owned JSON properties, which requires special handling.
320-
case nameof(RelationalDbFunctionsExtensions.JsonExists)
320+
case nameof(RelationalDbFunctionsExtensions.JsonPathExists)
321321
when declaringType == typeof(RelationalDbFunctionsExtensions)
322322
&& @object is null
323323
&& arguments is [_, var json, var path]:

src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ when methodCallExpression.Object is not null
236236
method.Name is nameof(string.StartsWith));
237237
}
238238

239-
// We translate EF.Functions.JsonExists here and not in a method translator since we need to support JsonExists over
239+
// We translate EF.Functions.JsonPathExists here and not in a method translator since we need to support JsonPathExists over
240240
// complex and owned JSON properties, which requires special handling.
241-
case nameof(RelationalDbFunctionsExtensions.JsonExists)
241+
case nameof(RelationalDbFunctionsExtensions.JsonPathExists)
242242
when declaringType == typeof(RelationalDbFunctionsExtensions)
243243
&& @object is null
244244
&& arguments is [_, var json, var path]:

test/EFCore.Relational.Specification.Tests/Query/Translations/JsonTranslationsRelationalTestBase.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77

88
namespace Microsoft.EntityFrameworkCore.Query.Translations;
99

10-
// This test suite covers translations of JSON functions on EF.Functions (e.g. EF.Functions.JsonExists).
10+
// This test suite covers translations of JSON functions on EF.Functions (e.g. EF.Functions.JsonPathExists).
1111
// It does not cover general, built-in JSON support via complex type mapping, etc.
1212
public abstract class JsonTranslationsRelationalTestBase<TFixture>(TFixture fixture) : QueryTestBase<TFixture>(fixture)
1313
where TFixture : JsonTranslationsRelationalTestBase<TFixture>.JsonTranslationsQueryFixtureBase, new()
1414
{
1515
[ConditionalFact]
16-
public virtual Task JsonExists_on_scalar_string_column()
16+
public virtual Task JsonPathExists_on_scalar_string_column()
1717
=> AssertQuery(
1818
ss => ss.Set<JsonTranslationsEntity>()
19-
.Where(b => EF.Functions.JsonExists(b.JsonString, "$.OptionalInt")),
19+
.Where(b => EF.Functions.JsonPathExists(b.JsonString, "$.OptionalInt")),
2020
ss => ss.Set<JsonTranslationsEntity>()
2121
.Where(b => ((IDictionary<string, JsonNode>)JsonNode.Parse(b.JsonString)!).ContainsKey("OptionalInt")));
2222

2323
[ConditionalFact]
24-
public virtual Task JsonExists_on_complex_property()
24+
public virtual Task JsonPathExists_on_complex_property()
2525
=> AssertQuery(
2626
ss => ss.Set<JsonTranslationsEntity>()
27-
.Where(b => EF.Functions.JsonExists(b.JsonComplexType, "$.OptionalInt")),
27+
.Where(b => EF.Functions.JsonPathExists(b.JsonComplexType, "$.OptionalInt")),
2828
ss => ss.Set<JsonTranslationsEntity>()
2929
.Where(b => ((IDictionary<string, JsonNode>)JsonNode.Parse(b.JsonString)!).ContainsKey("OptionalInt")));
3030

3131
[ConditionalFact]
32-
public virtual Task JsonExists_on_owned_entity()
32+
public virtual Task JsonPathExists_on_owned_entity()
3333
=> AssertQuery(
3434
ss => ss.Set<JsonTranslationsEntity>()
35-
.Where(b => EF.Functions.JsonExists(b.JsonOwnedType, "$.OptionalInt")),
35+
.Where(b => EF.Functions.JsonPathExists(b.JsonOwnedType, "$.OptionalInt")),
3636
ss => ss.Set<JsonTranslationsEntity>()
3737
.Where(b => ((IDictionary<string, JsonNode>)JsonNode.Parse(b.JsonString)!).ContainsKey("OptionalInt")));
3838

@@ -103,12 +103,12 @@ protected override async Task SeedAsync(JsonTranslationsQueryContext context)
103103

104104
await context.Database.ExecuteSqlRawAsync(
105105
$$"""
106-
UPDATE {{table}} SET {{complexTypeColumn}} = {{RemoveJsonProperty(complexTypeColumn, "$.OptionalInt")}} WHERE {{idColumn}} = 4;
107-
UPDATE {{table}} SET {{ownedColumn}} = {{RemoveJsonProperty(ownedColumn, "$.OptionalInt")}} WHERE {{idColumn}} = 4;
106+
UPDATE {{table}} SET {{complexTypeColumn}} = {{RemoveJsonProperty(complexTypeColumn, "OptionalInt")}} WHERE {{idColumn}} = 4;
107+
UPDATE {{table}} SET {{ownedColumn}} = {{RemoveJsonProperty(ownedColumn, "OptionalInt")}} WHERE {{idColumn}} = 4;
108108
""");
109109
}
110110

111-
protected abstract string RemoveJsonProperty(string column, string jsonPath);
111+
protected abstract string RemoveJsonProperty(string column, string property);
112112

113113
public virtual ISetSource GetExpectedData()
114114
=> _expectedData ??= new JsonTranslationsData();

test/EFCore.SqlServer.FunctionalTests/Query/Translations/JsonTranslationsSqlServerTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public JsonTranslationsSqlServerTest(JsonTranslationsQuerySqlServerFixture fixtu
1515
}
1616

1717
[ConditionalFact, SqlServerCondition(SqlServerCondition.SupportsFunctions2022)]
18-
public override async Task JsonExists_on_scalar_string_column()
18+
public override async Task JsonPathExists_on_scalar_string_column()
1919
{
20-
await base.JsonExists_on_scalar_string_column();
20+
await base.JsonPathExists_on_scalar_string_column();
2121

2222
AssertSql(
2323
"""
@@ -28,9 +28,9 @@ WHERE JSON_PATH_EXISTS([j].[JsonString], N'$.OptionalInt') = 1
2828
}
2929

3030
[ConditionalFact, SqlServerCondition(SqlServerCondition.SupportsFunctions2022)]
31-
public override async Task JsonExists_on_complex_property()
31+
public override async Task JsonPathExists_on_complex_property()
3232
{
33-
await base.JsonExists_on_complex_property();
33+
await base.JsonPathExists_on_complex_property();
3434

3535
AssertSql(
3636
"""
@@ -41,9 +41,9 @@ WHERE JSON_PATH_EXISTS([j].[JsonComplexType], N'$.OptionalInt') = 1
4141
}
4242

4343
[ConditionalFact, SqlServerCondition(SqlServerCondition.SupportsFunctions2022)]
44-
public override async Task JsonExists_on_owned_entity()
44+
public override async Task JsonPathExists_on_owned_entity()
4545
{
46-
await base.JsonExists_on_owned_entity();
46+
await base.JsonPathExists_on_owned_entity();
4747

4848
AssertSql(
4949
"""
@@ -133,8 +133,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
133133
}
134134
}
135135

136-
protected override string RemoveJsonProperty(string column, string jsonPath)
137-
=> $"JSON_MODIFY({column}, '{jsonPath}', NULL)";
136+
protected override string RemoveJsonProperty(string column, string property)
137+
=> $"JSON_MODIFY({column}, '$.{property}', NULL)";
138138
}
139139

140140
[ConditionalFact]

test/EFCore.Sqlite.FunctionalTests/Query/Translations/JsonTranslationsSqliteTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public JsonTranslationsSqliteTest(JsonTranslationsQuerySqliteFixture fixture, IT
1313
}
1414

1515
[ConditionalFact]
16-
public override async Task JsonExists_on_scalar_string_column()
16+
public override async Task JsonPathExists_on_scalar_string_column()
1717
{
18-
await base.JsonExists_on_scalar_string_column();
18+
await base.JsonPathExists_on_scalar_string_column();
1919

2020
AssertSql(
2121
"""
@@ -26,9 +26,9 @@ WHERE json_type("j"."JsonString", '$.OptionalInt') IS NOT NULL
2626
}
2727

2828
[ConditionalFact]
29-
public override async Task JsonExists_on_complex_property()
29+
public override async Task JsonPathExists_on_complex_property()
3030
{
31-
await base.JsonExists_on_complex_property();
31+
await base.JsonPathExists_on_complex_property();
3232

3333
AssertSql(
3434
"""
@@ -39,9 +39,9 @@ WHERE json_type("j"."JsonComplexType", '$.OptionalInt') IS NOT NULL
3939
}
4040

4141
[ConditionalFact]
42-
public override async Task JsonExists_on_owned_entity()
42+
public override async Task JsonPathExists_on_owned_entity()
4343
{
44-
await base.JsonExists_on_owned_entity();
44+
await base.JsonPathExists_on_owned_entity();
4545

4646
AssertSql(
4747
"""
@@ -56,8 +56,8 @@ public class JsonTranslationsQuerySqliteFixture : JsonTranslationsQueryFixtureBa
5656
protected override ITestStoreFactory TestStoreFactory
5757
=> SqliteTestStoreFactory.Instance;
5858

59-
protected override string RemoveJsonProperty(string column, string jsonPath)
60-
=> $"json_remove({column}, '{jsonPath}')";
59+
protected override string RemoveJsonProperty(string column, string property)
60+
=> $"json_remove({column}, '$.{property}')";
6161
}
6262

6363
[ConditionalFact]

0 commit comments

Comments
 (0)