-
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.
Query: Introduce custom query root for TVF
- Avoids having to do special processing in other visitors - Visit's method's argument correctly in other visitor (this means that if there is a navigation expansion required for a parameter it will be done automatically) - Remove Nav expansion factory not needed anymore - Rename ExpressionPrinter.VisitList to VisitCollection and take IReadOnlyCollection, that is what most expression uses. - Remove unnecessary exception message. They are part of a larger work item. Resolves #20146
- Loading branch information
Showing
25 changed files
with
253 additions
and
222 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
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
18 changes: 2 additions & 16 deletions
18
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
80 changes: 80 additions & 0 deletions
80
src/EFCore.Relational/Query/Internal/QueryableFunctionQueryRootExpression.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,80 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal | ||
{ | ||
public class QueryableFunctionQueryRootExpression : QueryRootExpression | ||
{ | ||
//Since this is always generated while compiling there is no query provider associated | ||
public QueryableFunctionQueryRootExpression( | ||
[NotNull] IEntityType entityType, [NotNull] IDbFunction function, [NotNull] IReadOnlyCollection<Expression> arguments) | ||
: base(entityType) | ||
{ | ||
Check.NotNull(function, nameof(function)); | ||
Check.NotNull(arguments, nameof(arguments)); | ||
|
||
Function = function; | ||
Arguments = arguments; | ||
} | ||
|
||
public virtual IDbFunction Function { get; } | ||
public virtual IReadOnlyCollection<Expression> Arguments { get; } | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
{ | ||
var arguments = new List<Expression>(); | ||
var changed = false; | ||
foreach (var argument in Arguments) | ||
{ | ||
var newArgument = visitor.Visit(argument); | ||
arguments.Add(newArgument); | ||
changed |= argument != newArgument; | ||
} | ||
|
||
return changed | ||
? new QueryableFunctionQueryRootExpression(EntityType, Function, arguments) | ||
: this; | ||
} | ||
|
||
public override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.Append(Function.MethodInfo.DisplayName()); | ||
expressionPrinter.Append("("); | ||
expressionPrinter.VisitCollection(Arguments); | ||
expressionPrinter.Append(")"); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is QueryableFunctionQueryRootExpression queryRootExpression | ||
&& Equals(queryRootExpression)); | ||
|
||
private bool Equals(QueryableFunctionQueryRootExpression queryRootExpression) | ||
=> base.Equals(queryRootExpression) | ||
&& Equals(Function, queryRootExpression.Function) | ||
&& Arguments.SequenceEqual(queryRootExpression.Arguments, ExpressionEqualityComparer.Instance); | ||
|
||
public override int GetHashCode() | ||
{ | ||
var hashCode = new HashCode(); | ||
hashCode.Add(base.GetHashCode()); | ||
hashCode.Add(Function); | ||
foreach (var item in Arguments) | ||
{ | ||
hashCode.Add(item); | ||
} | ||
|
||
return hashCode.ToHashCode(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...Core.Relational/Query/Internal/QueryableFunctionToQueryRootConvertingExpressionVisitor.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,40 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal | ||
{ | ||
public class QueryableFunctionToQueryRootConvertingExpressionVisitor : ExpressionVisitor | ||
{ | ||
private readonly IModel _model; | ||
|
||
public QueryableFunctionToQueryRootConvertingExpressionVisitor([NotNull] IModel model) | ||
{ | ||
Check.NotNull(model, nameof(model)); | ||
|
||
_model = model; | ||
} | ||
|
||
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) | ||
{ | ||
var function = _model.FindDbFunction(methodCallExpression.Method); | ||
|
||
return function?.IsIQueryable == true | ||
? CreateQueryableFunctionQueryRootExpression(function, methodCallExpression.Arguments) | ||
: base.VisitMethodCall(methodCallExpression); | ||
} | ||
|
||
private Expression CreateQueryableFunctionQueryRootExpression( | ||
IDbFunction function, IReadOnlyCollection<Expression> arguments) | ||
{ | ||
var entityType = _model.FindEntityType(function.MethodInfo.ReturnType.GetGenericArguments()[0]); | ||
|
||
return new QueryableFunctionQueryRootExpression(entityType, function, arguments); | ||
} | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/EFCore.Relational/Query/Internal/RelationalNavigationExpandingExpressionVisitor.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...EFCore.Relational/Query/Internal/RelationalNavigationExpandingExpressionVisitorFactory.cs
This file was deleted.
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
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.