-
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 #15264 - QueryRewrite: incorporate query filters into nav rewrite
Also, fix to #13361 - Query: QueryFilters/Defining queries are not applied recursively When nav rewrite constructs new EntityQueryable it now looks into EntityType for any query filter annotations and applies them on top. Those predicates are parameterized and the parameters created are injected into the context as part of query execution expression. Query filters also fundamentally change how nav expansion creates new navigations - before navigations were being added one by one, so we could easily build the NavigationTree by a new node representing given INavigation. With query filters, the newly created navigation may contain arbitrarily complex NavigationTree structure already (if the query filter itself has some navigations). To support that, when we create new EntityQueryable for join or collection navigation, we need to visit it (creating NavigationExpansionExpression) and merge the resulting NavigationTree with the previous navigation tree.
- Loading branch information
Showing
31 changed files
with
961 additions
and
437 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
src/EFCore/Query/NavigationExpansion/MaterializeCollectionNavigationExpression.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,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.NavigationExpansion | ||
{ | ||
public class MaterializeCollectionNavigationExpression : Expression, IPrintable | ||
{ | ||
private Type _returnType; | ||
public MaterializeCollectionNavigationExpression(Expression operand, INavigation navigation) | ||
{ | ||
Operand = operand; | ||
Navigation = navigation; | ||
_returnType = navigation.ClrType; | ||
} | ||
|
||
public virtual Expression Operand { get; } | ||
public virtual INavigation Navigation { get; } | ||
|
||
public override ExpressionType NodeType => ExpressionType.Extension; | ||
public override Type Type => _returnType; | ||
public override bool CanReduce => false; | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
{ | ||
var newOperand = visitor.Visit(Operand); | ||
|
||
return Update(newOperand); | ||
} | ||
|
||
public virtual MaterializeCollectionNavigationExpression Update(Expression operand) | ||
=> operand != Operand | ||
? new MaterializeCollectionNavigationExpression(operand, Navigation) | ||
: this; | ||
|
||
public virtual void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.StringBuilder.Append($"MATERIALIZE_COLLECTION({ Navigation }, "); | ||
expressionPrinter.Visit(Operand); | ||
expressionPrinter.StringBuilder.Append(")"); | ||
} | ||
} | ||
} |
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
494 changes: 375 additions & 119 deletions
494
src/EFCore/Query/NavigationExpansion/NavigationExpansionHelpers.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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.