Skip to content

Commit f38a96c

Browse files
authored
Sync to 9.0.0-preview.3.24172.4 (#3153)
* Implement quoting for custom SqlExpressions * Type mapping visitor changes * React to SqlConstantExpression changes
1 parent 17fa8de commit f38a96c

36 files changed

+621
-626
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
pull_request:
1212

1313
env:
14-
dotnet_sdk_version: '8.0.100'
14+
dotnet_sdk_version: '9.0.100-preview.3.24204.13'
1515
postgis_version: 3
1616
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1717

.github/workflows/codeql-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ on:
2727
- cron: '30 22 * * 6'
2828

2929
env:
30-
dotnet_sdk_version: '8.0.100'
30+
dotnet_sdk_version: '9.0.100-preview.3.24204.13'
3131

3232
jobs:
3333
analyze:

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ImplicitUsings>true</ImplicitUsings>
1313
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1414

15-
<Copyright>Copyright 2023 © The Npgsql Development Team</Copyright>
15+
<Copyright>Copyright 2024 © The Npgsql Development Team</Copyright>
1616
<Company>Npgsql</Company>
1717
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1818
<PackageLicenseExpression>PostgreSQL</PackageLicenseExpression>

Directory.Packages.props

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<EFCoreVersion>9.0.0-preview.2.24128.4</EFCoreVersion>
4-
<MicrosoftExtensionsVersion>9.0.0-preview.2.24128.5</MicrosoftExtensionsVersion>
3+
<EFCoreVersion>9.0.0-preview.3.24172.4</EFCoreVersion>
4+
<MicrosoftExtensionsVersion>9.0.0-preview.3.24172.9</MicrosoftExtensionsVersion>
55
<NpgsqlVersion>8.0.2</NpgsqlVersion>
66
</PropertyGroup>
77

@@ -23,8 +23,12 @@
2323

2424
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
2525
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
26-
<PackageVersion Include="xunit" Version="2.6.1" />
27-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
26+
<!-- <PackageVersion Include="xunit" Version="2.6.7-pre.5" />-->
27+
<!-- <PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7-pre.8" />-->
28+
<PackageVersion Include="xunit" Version="2.7.1" />
29+
<PackageVersion Include="xunit.assert" Version="2.7.1" />
30+
<PackageVersion Include="xunit.core" Version="2.7.1" />
31+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
2832
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
2933
</ItemGroup>
3034
</Project>

EFCore.PG.sln.DotSettings

+1-206
Large diffs are not rendered by default.

global.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
3-
"version": "8.0.100-rc.2.23502.2",
3+
"version": "9.0.100-preview.3.24204.13",
44
"rollForward": "latestMajor",
5-
"allowPrerelease": "true"
5+
"allowPrerelease": true
66
}
77
}

src/EFCore.PG.NodaTime/Query/Internal/PendingDateTimeZoneProviderExpression.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ private PendingDateTimeZoneProviderExpression()
99
{
1010
}
1111

12+
public override Expression Quote()
13+
=> throw new UnreachableException("PendingDateTimeZoneProviderExpression is a temporary tree representation and should never be quoted");
14+
1215
protected override void Print(ExpressionPrinter expressionPrinter)
1316
=> expressionPrinter.Append("TZDB");
1417
}

src/EFCore.PG.NodaTime/Query/Internal/PendingZonedDateTimeExpression.cs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ internal PendingZonedDateTimeExpression(SqlExpression operand, SqlExpression tim
1212

1313
internal SqlExpression TimeZoneId { get; }
1414

15+
public override Expression Quote()
16+
=> throw new UnreachableException("PendingDateTimeZoneProviderExpression is a temporary tree representation and should never be quoted");
17+
1518
protected override void Print(ExpressionPrinter expressionPrinter)
1619
{
1720
expressionPrinter.Visit(Operand);

src/EFCore.PG/EFCore.PG.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Description>PostgreSQL/Npgsql provider for Entity Framework Core.</Description>
1010
<PackageTags>npgsql;postgresql;postgres;Entity Framework Core;entity-framework-core;ef;efcore;orm;sql</PackageTags>
1111
<PackageReadmeFile>README.md</PackageReadmeFile>
12+
<NoWarn>EF1003</NoWarn> <!-- Precompiled query is experimental -->
1213
</PropertyGroup>
1314

1415
<ItemGroup>

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlObjectToStringTranslator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public NpgsqlObjectToStringTranslator(IRelationalTypeMappingSource typeMappingSo
7878
_sqlExpressionFactory.Equal(instance, _sqlExpressionFactory.Constant(true)),
7979
_sqlExpressionFactory.Constant(true.ToString()))
8080
},
81-
_sqlExpressionFactory.Constant(null))
81+
_sqlExpressionFactory.Constant(null, typeof(string)))
8282
: _sqlExpressionFactory.Case(
8383
new[]
8484
{

src/EFCore.PG/Query/Expressions/Internal/PgAllExpression.cs

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/// </remarks>
99
public class PgAllExpression : SqlExpression, IEquatable<PgAllExpression>
1010
{
11+
private static ConstructorInfo? _quotingConstructor;
12+
1113
/// <inheritdoc />
1214
public override Type Type
1315
=> typeof(bool);
@@ -63,6 +65,16 @@ public virtual PgAllExpression Update(SqlExpression item, SqlExpression array)
6365
? new PgAllExpression(item, array, OperatorType, TypeMapping)
6466
: this;
6567

68+
/// <inheritdoc />
69+
public override Expression Quote()
70+
=> New(
71+
_quotingConstructor ??= typeof(PgAllExpression).GetConstructor(
72+
[typeof(SqlExpression), typeof(SqlExpression), typeof(PgAllOperatorType), typeof(RelationalTypeMapping)])!,
73+
Item.Quote(),
74+
Array.Quote(),
75+
Constant(OperatorType),
76+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
77+
6678
/// <inheritdoc />
6779
protected override Expression VisitChildren(ExpressionVisitor visitor)
6880
=> Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array));

src/EFCore.PG/Query/Expressions/Internal/PgAnyExpression.cs

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/// </remarks>
1212
public class PgAnyExpression : SqlExpression, IEquatable<PgAnyExpression>
1313
{
14+
private static ConstructorInfo? _quotingConstructor;
15+
1416
/// <inheritdoc />
1517
public override Type Type
1618
=> typeof(bool);
@@ -74,6 +76,16 @@ public virtual PgAnyExpression Update(SqlExpression item, SqlExpression array)
7476
? new PgAnyExpression(item, array, OperatorType, TypeMapping)
7577
: this;
7678

79+
/// <inheritdoc />
80+
public override Expression Quote()
81+
=> New(
82+
_quotingConstructor ??= typeof(PgAnyExpression).GetConstructor(
83+
[typeof(SqlExpression), typeof(SqlExpression), typeof(PgAllOperatorType), typeof(RelationalTypeMapping)])!,
84+
Item.Quote(),
85+
Array.Quote(),
86+
Constant(OperatorType),
87+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
88+
7789
/// <inheritdoc />
7890
protected override Expression VisitChildren(ExpressionVisitor visitor)
7991
=> Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array));

src/EFCore.PG/Query/Expressions/Internal/PgArrayIndexExpression.cs

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
99
/// </remarks>
1010
public class PgArrayIndexExpression : SqlExpression, IEquatable<PgArrayIndexExpression>
1111
{
12+
private static ConstructorInfo? _quotingConstructor;
13+
1214
/// <summary>
1315
/// The array being indexed.
1416
/// </summary>
@@ -75,6 +77,17 @@ public virtual PgArrayIndexExpression Update(SqlExpression array, SqlExpression
7577
? this
7678
: new PgArrayIndexExpression(array, index, IsNullable, Type, TypeMapping);
7779

80+
/// <inheritdoc />
81+
public override Expression Quote()
82+
=> New(
83+
_quotingConstructor ??= typeof(PgArrayIndexExpression).GetConstructor(
84+
[typeof(SqlExpression), typeof(SqlExpression), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
85+
Array.Quote(),
86+
Index.Quote(),
87+
Constant(IsNullable),
88+
Constant(Type),
89+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
90+
7891
/// <inheritdoc />
7992
protected override Expression VisitChildren(ExpressionVisitor visitor)
8093
=> Update((SqlExpression)visitor.Visit(Array), (SqlExpression)visitor.Visit(Index));

src/EFCore.PG/Query/Expressions/Internal/PgArraySliceExpression.cs

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
88
/// </remarks>
99
public class PgArraySliceExpression : SqlExpression, IEquatable<PgArraySliceExpression>
1010
{
11+
private static ConstructorInfo? _quotingConstructor;
12+
1113
/// <summary>
1214
/// The array being sliced.
1315
/// </summary>
@@ -72,6 +74,18 @@ public virtual PgArraySliceExpression Update(SqlExpression array, SqlExpression?
7274
? this
7375
: new PgArraySliceExpression(array, lowerBound, upperBound, IsNullable, Type, TypeMapping);
7476

77+
/// <inheritdoc />
78+
public override Expression Quote()
79+
=> New(
80+
_quotingConstructor ??= typeof(PgArraySliceExpression).GetConstructor(
81+
[typeof(SqlExpression), typeof(SqlExpression), typeof(SqlExpression), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
82+
Array.Quote(),
83+
RelationalExpressionQuotingUtilities.VisitOrNull(LowerBound),
84+
RelationalExpressionQuotingUtilities.VisitOrNull(UpperBound),
85+
Constant(IsNullable),
86+
Constant(Type),
87+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
88+
7589
/// <inheritdoc />
7690
protected override Expression VisitChildren(ExpressionVisitor visitor)
7791
=> Update(

src/EFCore.PG/Query/Expressions/Internal/PgBinaryExpression.cs

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
77
/// </summary>
88
public class PgBinaryExpression : SqlExpression
99
{
10+
private static ConstructorInfo? _quotingConstructor;
11+
1012
/// <summary>
1113
/// Creates a new instance of the <see cref="PgBinaryExpression" /> class.
1214
/// </summary>
@@ -74,6 +76,17 @@ public virtual PgBinaryExpression Update(SqlExpression left, SqlExpression right
7476
: this;
7577
}
7678

79+
/// <inheritdoc />
80+
public override Expression Quote()
81+
=> New(
82+
_quotingConstructor ??= typeof(PgBinaryExpression).GetConstructor(
83+
[typeof(PgExpressionType), typeof(SqlExpression), typeof(SqlExpression), typeof(Type), typeof(RelationalTypeMapping)])!,
84+
Constant(OperatorType),
85+
Left.Quote(),
86+
Right.Quote(),
87+
Constant(Type),
88+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
89+
7790
/// <inheritdoc />
7891
protected override void Print(ExpressionPrinter expressionPrinter)
7992
{

src/EFCore.PG/Query/Expressions/Internal/PgILikeExpression.cs

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// ReSharper disable once InconsistentNaming
77
public class PgILikeExpression : SqlExpression, IEquatable<PgILikeExpression>
88
{
9+
private static ConstructorInfo? _quotingConstructor;
10+
911
/// <summary>
1012
/// The match expression.
1113
/// </summary>
@@ -60,6 +62,16 @@ public virtual PgILikeExpression Update(
6062
? this
6163
: new PgILikeExpression(match, pattern, escapeChar, TypeMapping);
6264

65+
/// <inheritdoc />
66+
public override Expression Quote()
67+
=> New(
68+
_quotingConstructor ??= typeof(PgILikeExpression).GetConstructor(
69+
[typeof(SqlExpression), typeof(SqlExpression), typeof(SqlExpression), typeof(RelationalTypeMapping)])!,
70+
Match.Quote(),
71+
Pattern.Quote(),
72+
RelationalExpressionQuotingUtilities.VisitOrNull(EscapeChar),
73+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
74+
6375
/// <inheritdoc />
6476
public override bool Equals(object? obj)
6577
=> obj is PgILikeExpression other && Equals(other);

src/EFCore.PG/Query/Expressions/Internal/PgJsonTraversalExpression.cs

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// </summary>
66
public class PgJsonTraversalExpression : SqlExpression, IEquatable<PgJsonTraversalExpression>
77
{
8+
private static ConstructorInfo? _quotingConstructor;
9+
810
/// <summary>
911
/// The match expression.
1012
/// </summary>
@@ -56,6 +58,17 @@ public virtual PgJsonTraversalExpression Update(SqlExpression expression, IReadO
5658
? this
5759
: new PgJsonTraversalExpression(expression, path, ReturnsText, Type, TypeMapping);
5860

61+
/// <inheritdoc />
62+
public override Expression Quote()
63+
=> New(
64+
_quotingConstructor ??= typeof(PgJsonTraversalExpression).GetConstructor(
65+
[typeof(SqlExpression), typeof(IReadOnlyList<SqlExpression>), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
66+
Expression.Quote(),
67+
NewArrayInit(typeof(SqlExpression), initializers: Path.Select(a => a.Quote())),
68+
Constant(ReturnsText),
69+
Constant(Type),
70+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
71+
5972
/// <summary>
6073
/// Appends an additional path component to this <see cref="PgJsonTraversalExpression" /> and returns the result.
6174
/// </summary>

src/EFCore.PG/Query/Expressions/Internal/PgNewArrayExpression.cs

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
55
/// </summary>
66
public class PgNewArrayExpression : SqlExpression
77
{
8+
private static ConstructorInfo? _quotingConstructor;
9+
810
/// <summary>
911
/// Creates a new instance of the <see cref="PgNewArrayExpression" /> class.
1012
/// </summary>
@@ -74,6 +76,15 @@ public virtual PgNewArrayExpression Update(IReadOnlyList<SqlExpression> expressi
7476
: new PgNewArrayExpression(expressions, Type, TypeMapping);
7577
}
7678

79+
/// <inheritdoc />
80+
public override Expression Quote()
81+
=> New(
82+
_quotingConstructor ??= typeof(PgNewArrayExpression).GetConstructor(
83+
[typeof(IReadOnlyList<SqlExpression>), typeof(Type), typeof(RelationalTypeMapping)])!,
84+
NewArrayInit(typeof(SqlExpression), initializers: Expressions.Select(a => a.Quote())),
85+
Constant(Type),
86+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
87+
7788
/// <inheritdoc />
7889
protected override void Print(ExpressionPrinter expressionPrinter)
7990
{

src/EFCore.PG/Query/Expressions/Internal/PgRegexMatchExpression.cs

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
77
/// </summary>
88
public class PgRegexMatchExpression : SqlExpression, IEquatable<PgRegexMatchExpression>
99
{
10+
private static ConstructorInfo? _quotingConstructor;
11+
1012
/// <inheritdoc />
1113
public override Type Type
1214
=> typeof(bool);
@@ -58,6 +60,16 @@ public virtual PgRegexMatchExpression Update(SqlExpression match, SqlExpression
5860
? new PgRegexMatchExpression(match, pattern, Options, TypeMapping)
5961
: this;
6062

63+
/// <inheritdoc />
64+
public override Expression Quote()
65+
=> New(
66+
_quotingConstructor ??= typeof(PgRegexMatchExpression).GetConstructor(
67+
[typeof(SqlExpression), typeof(SqlExpression), typeof(RegexOptions), typeof(RelationalTypeMapping)])!,
68+
Match.Quote(),
69+
Pattern.Quote(),
70+
Constant(Options),
71+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
72+
6173
/// <inheritdoc />
6274
public virtual bool Equals(PgRegexMatchExpression? other)
6375
=> ReferenceEquals(this, other)

src/EFCore.PG/Query/Expressions/Internal/PgRowValueExpression.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
1111
/// </remarks>
1212
public class PgRowValueExpression : SqlExpression, IEquatable<PgRowValueExpression>
1313
{
14+
private static ConstructorInfo? _quotingConstructor;
15+
1416
/// <summary>
1517
/// The values of this PostgreSQL row value expression.
1618
/// </summary>
1719
public virtual IReadOnlyList<SqlExpression> Values { get; }
1820

1921
/// <inheritdoc />
20-
public PgRowValueExpression(IReadOnlyList<SqlExpression> values, Type type, RelationalTypeMapping? typeMapping = null)
22+
public PgRowValueExpression(
23+
IReadOnlyList<SqlExpression> values,
24+
Type type,
25+
RelationalTypeMapping? typeMapping = null)
2126
: base(type, typeMapping)
2227
{
2328
Check.NotNull(values, nameof(values));
@@ -64,6 +69,15 @@ public virtual PgRowValueExpression Update(IReadOnlyList<SqlExpression> values)
6469
? this
6570
: new PgRowValueExpression(values, Type);
6671

72+
/// <inheritdoc />
73+
public override Expression Quote()
74+
=> New(
75+
_quotingConstructor ??= typeof(PgRowValueExpression).GetConstructor(
76+
[typeof(IReadOnlyList<SqlExpression>), typeof(Type), typeof(RelationalTypeMapping)])!,
77+
NewArrayInit(typeof(SqlExpression), initializers: Values.Select(a => a.Quote())),
78+
Constant(Type),
79+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
80+
6781
/// <inheritdoc />
6882
protected override void Print(ExpressionPrinter expressionPrinter)
6983
{

src/EFCore.PG/Query/Expressions/Internal/PgUnknownBinaryExpression.cs

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/// </summary>
1010
public class PgUnknownBinaryExpression : SqlExpression, IEquatable<PgUnknownBinaryExpression>
1111
{
12+
private static ConstructorInfo? _quotingConstructor;
13+
1214
/// <summary>
1315
/// The left-hand expression.
1416
/// </summary>
@@ -59,6 +61,17 @@ public virtual PgUnknownBinaryExpression Update(SqlExpression left, SqlExpressio
5961
? this
6062
: new PgUnknownBinaryExpression(left, right, Operator, Type, TypeMapping);
6163

64+
/// <inheritdoc />
65+
public override Expression Quote()
66+
=> New(
67+
_quotingConstructor ??= typeof(PgUnknownBinaryExpression).GetConstructor(
68+
[typeof(SqlExpression), typeof(SqlExpression), typeof(string), typeof(Type), typeof(RelationalTypeMapping)])!,
69+
Left.Quote(),
70+
Right.Quote(),
71+
Constant(Operator),
72+
Constant(Type),
73+
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));
74+
6275
/// <inheritdoc />
6376
public virtual bool Equals(PgUnknownBinaryExpression? other)
6477
=> ReferenceEquals(this, other)

0 commit comments

Comments
 (0)