Skip to content

Commit 8332c31

Browse files
committed
Sync to EF 10.0.0-preview.7.25352.2
1 parent fb96538 commit 8332c31

15 files changed

+139
-99
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<EFCoreVersion>10.0.0-preview.6.25321.102</EFCoreVersion>
4-
<MicrosoftExtensionsVersion>10.0.0-preview.6.25321.102</MicrosoftExtensionsVersion>
3+
<EFCoreVersion>10.0.0-preview.7.25352.2</EFCoreVersion>
4+
<MicrosoftExtensionsVersion>10.0.0-preview.7.25351.105</MicrosoftExtensionsVersion>
55
<NpgsqlVersion>9.0.3</NpgsqlVersion>
66
</PropertyGroup>
77

src/EFCore.PG/Query/Internal/NpgsqlParameterBasedSqlProcessor.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,16 @@ public NpgsqlParameterBasedSqlProcessor(
2727
/// any release. You should only use it directly in your code with extreme caution and knowing that
2828
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2929
/// </summary>
30-
public override Expression Optimize(
31-
Expression queryExpression,
32-
IReadOnlyDictionary<string, object?> parametersValues,
33-
out bool canCache)
30+
public override Expression Process(Expression queryExpression, CacheSafeParameterFacade parametersFacade)
3431
{
35-
queryExpression = base.Optimize(queryExpression, parametersValues, out canCache);
32+
queryExpression = base.Process(queryExpression, parametersFacade);
3633

3734
queryExpression = new NpgsqlDeleteConvertingExpressionVisitor().Process(queryExpression);
3835

3936
return queryExpression;
4037
}
4138

4239
/// <inheritdoc />
43-
protected override Expression ProcessSqlNullability(
44-
Expression selectExpression,
45-
IReadOnlyDictionary<string, object?> parametersValues,
46-
out bool canCache)
47-
{
48-
Check.NotNull(selectExpression, nameof(selectExpression));
49-
Check.NotNull(parametersValues, nameof(parametersValues));
50-
51-
return new NpgsqlSqlNullabilityProcessor(Dependencies, Parameters).Process(
52-
selectExpression, parametersValues, out canCache);
53-
}
40+
protected override Expression ProcessSqlNullability(Expression selectExpression, CacheSafeParameterFacade parametersFacade)
41+
=> new NpgsqlSqlNullabilityProcessor(Dependencies, Parameters).Process(selectExpression, parametersFacade);
5442
}

src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,5 @@ private static bool MayContainNulls(SqlExpression arrayExpression)
737737
// Note that we can check parameter values for null since we cache by the parameter nullability; but we cannot do the same for bool.
738738
private bool IsNull(SqlExpression? expression)
739739
=> expression is SqlConstantExpression { Value: null }
740-
|| expression is SqlParameterExpression { Name: string parameterName } && ParameterValues[parameterName] is null;
740+
|| expression is SqlParameterExpression { Name: string parameterName } && ParametersFacade.IsParameterNull(parameterName);
741741
}

src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ private bool TryTranslateStartsEndsWithContains(
611611
QueryContext queryContext,
612612
string baseParameterName,
613613
StartsEndsWithContains methodType)
614-
=> queryContext.ParameterValues[baseParameterName] switch
614+
=> queryContext.Parameters[baseParameterName] switch
615615
{
616616
null => null,
617617

src/Shared/Check.cs

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
16
using System.Diagnostics.CodeAnalysis;
7+
using System.Runtime.CompilerServices;
28
using JetBrains.Annotations;
39

410
namespace Microsoft.EntityFrameworkCore.Utilities;
@@ -8,13 +14,13 @@ internal static class Check
814
{
915
[ContractAnnotation("value:null => halt")]
1016
[return: NotNull]
11-
public static T NotNull<T>([NoEnumeration] [AllowNull] [NotNull] T value, [InvokerParameterName] string parameterName)
17+
public static T NotNull<T>(
18+
[NoEnumeration, AllowNull, NotNull] T value,
19+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
1220
{
1321
if (value is null)
1422
{
15-
NotEmpty(parameterName, nameof(parameterName));
16-
17-
throw new ArgumentNullException(parameterName);
23+
ThrowArgumentNull(parameterName);
1824
}
1925

2026
return value;
@@ -23,108 +29,123 @@ public static T NotNull<T>([NoEnumeration] [AllowNull] [NotNull] T value, [Invok
2329
[ContractAnnotation("value:null => halt")]
2430
public static IReadOnlyList<T> NotEmpty<T>(
2531
[NotNull] IReadOnlyList<T>? value,
26-
[InvokerParameterName] string parameterName)
32+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
2733
{
2834
NotNull(value, parameterName);
2935

3036
if (value.Count == 0)
3137
{
32-
NotEmpty(parameterName, nameof(parameterName));
33-
34-
throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(parameterName));
38+
ThrowNotEmpty(parameterName);
3539
}
3640

3741
return value;
3842
}
3943

4044
[ContractAnnotation("value:null => halt")]
41-
public static string NotEmpty([NotNull] string? value, [InvokerParameterName] string parameterName)
45+
public static string NotEmpty(
46+
[NotNull] string? value,
47+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
4248
{
43-
if (value is null)
44-
{
45-
NotEmpty(parameterName, nameof(parameterName));
46-
throw new ArgumentNullException(parameterName);
47-
}
49+
NotNull(value, parameterName);
4850

49-
if (value.Trim().Length == 0)
51+
if (value.AsSpan().Trim().Length == 0)
5052
{
51-
NotEmpty(parameterName, nameof(parameterName));
52-
throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
53+
ThrowStringArgumentEmpty(parameterName);
5354
}
5455

5556
return value;
5657
}
5758

58-
public static string? NullButNotEmpty(string? value, [InvokerParameterName] string parameterName)
59+
public static IReadOnlyCollection<T>? NullButNotEmpty<T>(
60+
IReadOnlyCollection<T>? value,
61+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
5962
{
60-
if (value is not null && value.Length == 0)
63+
if (value is not null && value.Count == 0)
6164
{
62-
NotEmpty(parameterName, nameof(parameterName));
63-
64-
throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
65+
ThrowStringArgumentEmpty(parameterName);
6566
}
6667

6768
return value;
6869
}
6970

70-
public static IReadOnlyCollection<T>? NullButNotEmpty<T>(
71-
IReadOnlyCollection<T>? value,
72-
[InvokerParameterName] string parameterName)
71+
public static string? NullButNotEmpty(
72+
string? value,
73+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
7374
{
74-
if (value is { Count: 0 })
75+
if (value is not null && value.Length == 0)
7576
{
76-
NotEmpty(parameterName, nameof(parameterName));
77-
78-
throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
77+
ThrowStringArgumentEmpty(parameterName);
7978
}
8079

8180
return value;
8281
}
8382

8483
public static IReadOnlyList<T> HasNoNulls<T>(
8584
[NotNull] IReadOnlyList<T>? value,
86-
[InvokerParameterName] string parameterName)
85+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
8786
where T : class
8887
{
8988
NotNull(value, parameterName);
9089

91-
if (value.Any(e => e is null))
90+
for (var i = 0; i < value.Count; i++)
9291
{
93-
NotEmpty(parameterName, nameof(parameterName));
94-
95-
throw new ArgumentException(parameterName);
92+
if (value[i] is null)
93+
{
94+
ThrowArgumentException(parameterName, parameterName);
95+
}
9696
}
9797

9898
return value;
9999
}
100100

101101
public static IReadOnlyList<string> HasNoEmptyElements(
102102
[NotNull] IReadOnlyList<string>? value,
103-
[InvokerParameterName] string parameterName)
103+
[InvokerParameterName, CallerArgumentExpression(nameof(value))] string parameterName = "")
104104
{
105105
NotNull(value, parameterName);
106106

107-
if (value.Any(s => string.IsNullOrWhiteSpace(s)))
107+
for (var i = 0; i < value.Count; i++)
108108
{
109-
NotEmpty(parameterName, nameof(parameterName));
110-
111-
throw new ArgumentException(AbstractionsStrings.CollectionArgumentHasEmptyElements(parameterName));
109+
if (string.IsNullOrWhiteSpace(value[i]))
110+
{
111+
ThrowCollectionHasEmptyElements(parameterName);
112+
}
112113
}
113114

114115
return value;
115116
}
116117

117118
[Conditional("DEBUG")]
118-
public static void DebugAssert([DoesNotReturnIf(false)] bool condition, string message)
119+
public static void DebugAssert([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition))] string message = "")
119120
{
120121
if (!condition)
121122
{
122-
throw new Exception($"Check.DebugAssert failed: {message}");
123+
throw new UnreachableException($"Check.DebugAssert failed: {message}");
123124
}
124125
}
125126

126127
[Conditional("DEBUG")]
127128
[DoesNotReturn]
128129
public static void DebugFail(string message)
129-
=> throw new Exception($"Check.DebugFail failed: {message}");
130+
=> throw new UnreachableException($"Check.DebugFail failed: {message}");
131+
132+
[DoesNotReturn]
133+
private static void ThrowArgumentNull(string parameterName)
134+
=> throw new ArgumentNullException(parameterName);
135+
136+
[DoesNotReturn]
137+
private static void ThrowNotEmpty(string parameterName)
138+
=> throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty, parameterName);
139+
140+
[DoesNotReturn]
141+
private static void ThrowStringArgumentEmpty(string parameterName)
142+
=> throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty, parameterName);
143+
144+
[DoesNotReturn]
145+
private static void ThrowCollectionHasEmptyElements(string parameterName)
146+
=> throw new ArgumentException(AbstractionsStrings.CollectionArgumentHasEmptyElements, parameterName);
147+
148+
[DoesNotReturn]
149+
private static void ThrowArgumentException(string message, string parameterName)
150+
=> throw new ArgumentException(message, parameterName);
130151
}

test/EFCore.PG.FunctionalTests/Query/AdHocMiscellaneousQueryNpgsqlTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public class AdHocMiscellaneousQueryNpgsqlTest(NonSharedFixture fixture) : AdHoc
77
protected override ITestStoreFactory TestStoreFactory
88
=> NpgsqlTestStoreFactory.Instance;
99

10-
protected override DbContextOptionsBuilder SetTranslateParameterizedCollectionsToConstants(DbContextOptionsBuilder optionsBuilder)
10+
protected override DbContextOptionsBuilder SetParameterizedCollectionMode(DbContextOptionsBuilder optionsBuilder, ParameterizedCollectionMode parameterizedCollectionMode)
1111
{
12-
new NpgsqlDbContextOptionsBuilder(optionsBuilder).TranslateParameterizedCollectionsToConstants();
12+
new NpgsqlDbContextOptionsBuilder(optionsBuilder).UseParameterizedCollectionMode(parameterizedCollectionMode);
1313

1414
return optionsBuilder;
1515
}

test/EFCore.PG.FunctionalTests/Query/CompatibilityQueryNpgsqlTest.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ public async Task Array_contains_is_not_parameterized_with_array_on_redshift()
1717
{
1818
var ctx = CreateRedshiftContext();
1919

20-
var numbers = new[] { 8, 9 };
21-
var result = await ctx.TestEntities.Where(e => numbers.Contains(e.SomeInt)).SingleAsync();
22-
Assert.Equal(1, result.Id);
23-
24-
AssertSql(
25-
"""
26-
SELECT t."Id", t."SomeInt"
27-
FROM "TestEntities" AS t
28-
WHERE t."SomeInt" IN (?, ?)
29-
LIMIT 2
30-
""");
20+
// https://github.com/dotnet/efcore/issues/36311
21+
await Assert.ThrowsAsync<UnreachableException>(async () =>
22+
{
23+
var numbers = new[] { 8, 9 };
24+
var result = await ctx.TestEntities.Where(e => numbers.Contains(e.SomeInt)).SingleAsync();
25+
Assert.Equal(1, result.Id);
26+
27+
AssertSql(
28+
"""
29+
SELECT t."Id", t."SomeInt"
30+
FROM "TestEntities" AS t
31+
WHERE t."SomeInt" IN (?, ?)
32+
LIMIT 2
33+
""");
34+
});
3135
}
3236

3337
#region Support

test/EFCore.PG.FunctionalTests/Query/ComplexNavigationsQueryNpgsqlTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ public override Task GroupJoin_client_method_in_OrderBy(bool async)
2020
CoreStrings.QueryUnableToTranslateMethod(
2121
"Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase<Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryNpgsqlFixture>",
2222
"ClientMethodNullableInt"));
23-
24-
public override Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async)
25-
=> Assert.ThrowsAsync<EqualException>(
26-
async () => await base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async));
2723
}

test/EFCore.PG.FunctionalTests/Query/ComplexNavigationsSharedTypeQueryNpgsqlTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public override Task GroupJoin_client_method_in_OrderBy(bool async)
3030
"Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase<Microsoft.EntityFrameworkCore.Query.ComplexNavigationsSharedTypeQueryNpgsqlFixture>",
3131
"ClientMethodNullableInt"));
3232

33-
public override Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async)
34-
=> Assert.ThrowsAsync<EqualException>(
35-
async () => await base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async));
36-
3733
[ConditionalTheory(Skip = "https://github.com/dotnet/efcore/issues/26104")]
3834
public override Task GroupBy_aggregate_where_required_relationship(bool async)
3935
=> base.GroupBy_aggregate_where_required_relationship(async);

test/EFCore.PG.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryNpgsqlTest.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ namespace Microsoft.EntityFrameworkCore.Query;
55
public class NonSharedPrimitiveCollectionsQueryNpgsqlTest(NonSharedFixture fixture)
66
: NonSharedPrimitiveCollectionsQueryRelationalTestBase(fixture)
77
{
8+
protected override DbContextOptionsBuilder SetParameterizedCollectionMode(DbContextOptionsBuilder optionsBuilder, ParameterizedCollectionMode parameterizedCollectionMode)
9+
{
10+
new NpgsqlDbContextOptionsBuilder(optionsBuilder).UseParameterizedCollectionMode(parameterizedCollectionMode);
11+
12+
return optionsBuilder;
13+
}
14+
815
#region Support for specific element types
916

1017
// Since we just use arrays for primitive collections, there's no need to test each and every element type; arrays are fully typed
@@ -95,20 +102,6 @@ LIMIT 2
95102
""");
96103
}
97104

98-
protected override DbContextOptionsBuilder SetTranslateParameterizedCollectionsToConstants(DbContextOptionsBuilder optionsBuilder)
99-
{
100-
new NpgsqlDbContextOptionsBuilder(optionsBuilder).TranslateParameterizedCollectionsToConstants();
101-
102-
return optionsBuilder;
103-
}
104-
105-
protected override DbContextOptionsBuilder SetTranslateParameterizedCollectionsToParameters(DbContextOptionsBuilder optionsBuilder)
106-
{
107-
new NpgsqlDbContextOptionsBuilder(optionsBuilder).TranslateParameterizedCollectionsToParameters();
108-
109-
return optionsBuilder;
110-
}
111-
112105
protected override ITestStoreFactory TestStoreFactory
113106
=> NpgsqlTestStoreFactory.Instance;
114107
}

0 commit comments

Comments
 (0)