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
90 changed files
with
5,594 additions
and
598 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
6 changes: 6 additions & 0 deletions
6
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
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
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
// 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) | ||
{ | ||
// TODO: Decide whether this belongs here or in specific provider code. This means parameter query roots always get created | ||
// (in enumerable/queryable context), but may not be translatable in the provider's QueryableMethodTranslatingEV. As long | ||
// as we unwrap there, we *should* be OK, and so don't need an additional provider extension point here... | ||
|
||
// TODO: Also, maybe this type checking should be in the base class. | ||
// SQL Server's OpenJson, which we use to unpack the queryable parameter, does not support geometry (or any other non-built-in | ||
// types) | ||
|
||
// 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). | ||
return _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.