-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to #28648 - Json/Query: translate element access of a json array
Converting indexer into AsQueryable().ElementAt(x) so that nav expansion can understand it and inject MaterializeCollectionNavigationExpression in the right places. Then in translation we recognize the pattern and convert it back to element access on a JsonQueryExpression. In order to shape the results correctly, we need to add all the array indexes (that are not constants) to the projection, so that we can populate the ordinal keys correctly (and also to do de-duplication). Fixes #28648
- Loading branch information
Showing
12 changed files
with
815 additions
and
29 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...Core.Relational/Query/Internal/CollectionIndexerToElementAtConvertingExpressionVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
internal class CollectionIndexerToElementAtConvertingExpressionVisitor : ExpressionVisitor | ||
{ | ||
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) | ||
{ | ||
if (methodCallExpression.Method.Name == "get_Item" | ||
&& !methodCallExpression.Method.IsStatic | ||
&& methodCallExpression.Method.DeclaringType != null | ||
&& methodCallExpression.Method.DeclaringType != typeof(string) | ||
&& methodCallExpression.Method.DeclaringType != typeof(byte[]) | ||
&& ((methodCallExpression.Method.DeclaringType.IsGenericType | ||
&& methodCallExpression.Method.DeclaringType.GetGenericTypeDefinition() == typeof(List<>)) | ||
|| methodCallExpression.Method.DeclaringType.IsArray)) | ||
{ | ||
var source = Visit(methodCallExpression.Object!); | ||
var index = Visit(methodCallExpression.Arguments[0]); | ||
var sourceTypeArgument = source.Type.GetSequenceType(); | ||
|
||
return Expression.Call( | ||
QueryableMethods.ElementAt.MakeGenericMethod(sourceTypeArgument), | ||
Expression.Call( | ||
QueryableMethods.AsQueryable.MakeGenericMethod(sourceTypeArgument), | ||
source), | ||
index); | ||
} | ||
|
||
return base.VisitMethodCall(methodCallExpression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.