forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes dotnet#29427 Closes dotnet#30426 Closes dotnet#13617
- Loading branch information
Showing
82 changed files
with
6,430 additions
and
463 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
14 changes: 14 additions & 0 deletions
14
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
47 changes: 0 additions & 47 deletions
47
...re.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.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
73 changes: 73 additions & 0 deletions
73
src/EFCore.Relational/Query/RelationalQueryRootProcessor.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,73 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
/// <inheritdoc /> | ||
public class RelationalQueryRootProcessor : QueryRootProcessor | ||
{ | ||
private readonly ITypeMappingSource _typeMappingSource; | ||
private readonly IModel _model; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="RelationalQueryRootProcessor" /> class. | ||
/// </summary> | ||
/// <param name="typeMappingSource">The type mapping source.</param> | ||
/// <param name="model">The model.</param> | ||
public RelationalQueryRootProcessor(ITypeMappingSource typeMappingSource, IModel model) | ||
{ | ||
_typeMappingSource = typeMappingSource; | ||
_model = model; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) | ||
{ | ||
// Create query root node for table-valued functions | ||
if (_model.FindDbFunction(methodCallExpression.Method) is { IsScalar: false, StoreFunction: var storeFunction }) | ||
{ | ||
// See issue #19970 | ||
return new TableValuedFunctionQueryRootExpression( | ||
storeFunction.EntityTypeMappings.Single().EntityType, | ||
storeFunction, | ||
methodCallExpression.Arguments); | ||
} | ||
|
||
return base.VisitMethodCall(methodCallExpression); | ||
} | ||
|
||
/// <summary> | ||
/// Given a queryable constants over an element type which has a type mapping, converts it to a | ||
/// <see cref="ConstantQueryRootExpression" />; it will be translated to a SQL <see cref="ValuesExpression" />. | ||
/// </summary> | ||
/// <param name="constantExpression">The constant expression to attempt to convert to a query root.</param> | ||
protected override Expression VisitQueryableConstant(ConstantExpression constantExpression) | ||
// TODO: Note that we restrict to constants whose element type is mappable as-is. This excludes a constant list with an unsupported | ||
// CLR type, where we could infer a type mapping with a value converter based on its later usage. However, converting all constant | ||
// collections to query roots also carries risk. | ||
=> constantExpression.Type.TryGetSequenceType() is Type elementType && _typeMappingSource.FindMapping(elementType) is not null | ||
? new ConstantQueryRootExpression(constantExpression) | ||
: constantExpression; | ||
|
||
/// <inheritdoc /> | ||
protected override Expression VisitQueryableParameter(ParameterExpression parameterExpression) | ||
// We convert to query roots only parameters whose CLR type has a collection type mapping (i.e. ElementTypeMapping isn't null). | ||
// This allows the provider to determine exactly which types are supported as queryable collections (e.g. OPENJSON on SQL Server). | ||
=> _typeMappingSource.FindMapping(parameterExpression.Type) is { ElementTypeMapping: not null } | ||
? new ParameterQueryRootExpression(parameterExpression.Type.GetSequenceType(), parameterExpression) | ||
: parameterExpression; | ||
|
||
/// <inheritdoc /> | ||
protected override Expression VisitExtension(Expression node) | ||
=> node switch | ||
{ | ||
// We skip FromSqlQueryRootExpression, since that contains the arguments as an object array parameter, and don't want to convert | ||
// that to a query root | ||
FromSqlQueryRootExpression e => e, | ||
|
||
_ => base.VisitExtension(node) | ||
}; | ||
} |
Oops, something went wrong.