Skip to content

Commit 59389e5

Browse files
authored
Minor changes resulting from PG sync work to rc1 (#31581)
1 parent 6af7161 commit 59389e5

File tree

34 files changed

+191
-142
lines changed

34 files changed

+191
-142
lines changed

src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,17 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
182182

183183
if (expression is MethodCallExpression methodCallExpression)
184184
{
185-
if (methodCallExpression.Method.IsGenericMethod
186-
&& methodCallExpression.Method.DeclaringType == typeof(Enumerable)
187-
&& methodCallExpression.Method.Name == nameof(Enumerable.ToList)
188-
&& methodCallExpression.Arguments.Count == 1
189-
&& methodCallExpression.Arguments[0].Type.TryGetElementType(typeof(IQueryable<>)) != null)
185+
if (methodCallExpression is
186+
{
187+
Method.IsGenericMethod: true,
188+
Method.Name: nameof(Enumerable.ToList),
189+
Method: var method,
190+
Arguments: [var argument]
191+
}
192+
&& method.DeclaringType == typeof(Enumerable)
193+
&& argument.Type.TryGetElementType(typeof(IQueryable<>)) != null)
190194
{
191-
var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
192-
methodCallExpression.Arguments[0]);
193-
if (subquery != null)
195+
if (_queryableMethodTranslatingExpressionVisitor.TranslateSubquery(argument) is ShapedQueryExpression subquery)
194196
{
195197
_clientProjections!.Add(subquery);
196198
// expression.Type here will be List<T>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
3838
/// </summary>
3939
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
4040
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
41-
public virtual CrossApplyExpression Update(TableExpressionBase table)
41+
public override CrossApplyExpression Update(TableExpressionBase table)
4242
=> table != Table
4343
? new CrossApplyExpression(table, GetAnnotations())
4444
: this;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
3838
/// </summary>
3939
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
4040
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
41-
public virtual CrossJoinExpression Update(TableExpressionBase table)
41+
public override CrossJoinExpression Update(TableExpressionBase table)
4242
=> table != Table
4343
? new CrossJoinExpression(table, GetAnnotations())
4444
: this;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
4848
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
4949
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
5050
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
51-
public virtual InnerJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
51+
public override InnerJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
5252
=> table != Table || joinPredicate != JoinPredicate
5353
? new InnerJoinExpression(table, joinPredicate, GetAnnotations())
5454
: this;
5555

56+
/// <summary>
57+
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
58+
/// return this expression.
59+
/// </summary>
60+
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
61+
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
62+
public override InnerJoinExpression Update(TableExpressionBase table)
63+
=> table != Table
64+
? new InnerJoinExpression(table, JoinPredicate, GetAnnotations())
65+
: this;
66+
5667
/// <inheritdoc />
5768
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)
5869
=> new InnerJoinExpression(Table, JoinPredicate, annotations);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ protected JoinExpressionBase(TableExpressionBase table, IEnumerable<IAnnotation>
3939
/// </summary>
4040
public virtual TableExpressionBase Table { get; }
4141

42+
/// <summary>
43+
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
44+
/// return this expression.
45+
/// </summary>
46+
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
47+
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
48+
public abstract JoinExpressionBase Update(TableExpressionBase table);
49+
4250
/// <inheritdoc />
4351
public override bool Equals(object? obj)
4452
=> obj != null

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
4848
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
4949
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
5050
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
51-
public virtual LeftJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
51+
public override LeftJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
5252
=> table != Table || joinPredicate != JoinPredicate
5353
? new LeftJoinExpression(table, joinPredicate, GetAnnotations())
5454
: this;
5555

56+
/// <summary>
57+
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
58+
/// return this expression.
59+
/// </summary>
60+
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
61+
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
62+
public override LeftJoinExpression Update(TableExpressionBase table)
63+
=> table != Table
64+
? new LeftJoinExpression(table, JoinPredicate, GetAnnotations())
65+
: this;
66+
5667
/// <inheritdoc />
5768
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)
5869
=> new LeftJoinExpression(Table, JoinPredicate, annotations);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
3838
/// </summary>
3939
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
4040
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
41-
public virtual OuterApplyExpression Update(TableExpressionBase table)
41+
public override OuterApplyExpression Update(TableExpressionBase table)
4242
=> table != Table
4343
? new OuterApplyExpression(table, GetAnnotations())
4444
: this;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ protected PredicateJoinExpressionBase(
4444
/// </summary>
4545
public virtual SqlExpression JoinPredicate { get; }
4646

47+
/// <summary>
48+
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
49+
/// return this expression.
50+
/// </summary>
51+
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
52+
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
53+
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
54+
public abstract PredicateJoinExpressionBase Update(TableExpressionBase table, SqlExpression joinPredicate);
55+
4756
/// <inheritdoc />
4857
public override bool Equals(object? obj)
4958
=> obj != null

src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
225225
Type? providerType,
226226
CoreTypeMapping? elementMapping)
227227
{
228-
var elementType = modelType.TryGetElementType(typeof(IEnumerable<>))!;
228+
if (TryFindJsonCollectionMapping(
229+
info.CoreTypeMappingInfo, modelType, providerType, ref elementMapping, out var collectionReaderWriter))
230+
{
231+
var elementType = modelType.TryGetElementType(typeof(IEnumerable<>))!;
229232

230-
return TryFindJsonCollectionMapping(
231-
info.CoreTypeMappingInfo, modelType, providerType, ref elementMapping, out var collectionReaderWriter)
232-
? (RelationalTypeMapping)FindMapping(
233+
return (RelationalTypeMapping)FindMapping(
233234
info.WithConverter(
234235
// Note that the converter info is only used temporarily here and never creates an instance.
235236
new ValueConverterInfo(modelType, typeof(string), _ => null!)))!
@@ -242,8 +243,10 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
242243
: typeof(ListComparer<>).MakeGenericType(elementMapping!.Comparer.Type),
243244
elementMapping!.Comparer),
244245
elementMapping,
245-
collectionReaderWriter)
246-
: null;
246+
collectionReaderWriter);
247+
}
248+
249+
return null;
247250
}
248251

249252
/// <summary>

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ public virtual Expression Process(Expression expression)
9292

9393
table = table switch
9494
{
95-
InnerJoinExpression ij => ij.Update(newOpenJsonExpression, ij.JoinPredicate),
96-
LeftJoinExpression lj => lj.Update(newOpenJsonExpression, lj.JoinPredicate),
97-
CrossJoinExpression cj => cj.Update(newOpenJsonExpression),
98-
CrossApplyExpression ca => ca.Update(newOpenJsonExpression),
99-
OuterApplyExpression oa => oa.Update(newOpenJsonExpression),
100-
_ => newOpenJsonExpression,
95+
JoinExpressionBase j => j.Update(newOpenJsonExpression),
96+
SqlServerOpenJsonExpression => newOpenJsonExpression,
97+
_ => throw new UnreachableException()
10198
};
10299

103100
foreach (var columnInfo in openJsonExpression.ColumnInfos!)

0 commit comments

Comments
 (0)