Class QueryableMethodTranslatingExpressionVisitor
- Namespace
- Microsoft.EntityFrameworkCore.Query
- Assembly
- Microsoft.EntityFrameworkCore.dll
A class that translates queryable methods in a query.
This type is typically used by database providers (and other extensions). It is generally not used in application code.
public abstract class QueryableMethodTranslatingExpressionVisitor : ExpressionVisitor
- Inheritance
-
QueryableMethodTranslatingExpressionVisitor
- Inherited Members
Remarks
See Implementation of database providers and extensions and How EF Core queries work for more information and examples.
Constructors
QueryableMethodTranslatingExpressionVisitor(QueryableMethodTranslatingExpressionVisitorDependencies, QueryCompilationContext, bool)
Creates a new instance of the QueryableMethodTranslatingExpressionVisitor class.
protected QueryableMethodTranslatingExpressionVisitor(QueryableMethodTranslatingExpressionVisitorDependencies dependencies, QueryCompilationContext queryCompilationContext, bool subquery)
Parameters
dependencies
QueryableMethodTranslatingExpressionVisitorDependenciesParameter object containing dependencies for this class.
queryCompilationContext
QueryCompilationContextThe query compilation context object to use.
subquery
boolA bool value indicating whether it is for a subquery translation.
Properties
Dependencies
Dependencies for this service.
protected virtual QueryableMethodTranslatingExpressionVisitorDependencies Dependencies { get; }
Property Value
QueryCompilationContext
The query compilation context object for current compilation.
protected virtual QueryCompilationContext QueryCompilationContext { get; }
Property Value
TranslationErrorDetails
Detailed information about errors encountered during translation.
public virtual string? TranslationErrorDetails { get; }
Property Value
Methods
AddTranslationErrorDetails(string)
Adds detailed information about errors encountered during translation.
protected virtual void AddTranslationErrorDetails(string details)
Parameters
details
stringError encountered during translation.
CreateShapedQueryExpression(IEntityType)
Creates a ShapedQueryExpression for the given entity type.
protected abstract ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType)
Parameters
entityType
IEntityTypeThe entity type.
Returns
- ShapedQueryExpression
A shaped query expression for the given entity type.
CreateSubqueryVisitor()
Creates a visitor customized to translate a subquery through TranslateSubquery(Expression).
protected abstract QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor()
Returns
- QueryableMethodTranslatingExpressionVisitor
A visitor to translate subquery.
MarkShaperNullable(Expression)
Marks the entity shaper in the given shaper expression as nullable.
protected virtual Expression MarkShaperNullable(Expression shaperExpression)
Parameters
shaperExpression
ExpressionThe shaper expression to process.
Returns
- Expression
New shaper expression in which all entity shapers are nullable.
Translate(Expression)
Translates an expression to an equivalent SQL representation.
public virtual Expression Translate(Expression expression)
Parameters
expression
ExpressionAn expression to translate.
Returns
- Expression
A SQL translation of the given expression.
TranslateAll(ShapedQueryExpression, LambdaExpression)
Translates All<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateAny(ShapedQueryExpression, LambdaExpression?)
Translates Any<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateAny(ShapedQueryExpression source, LambdaExpression? predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateAverage(ShapedQueryExpression, LambdaExpression?, Type)
Translates Average(IQueryable<decimal>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateAverage(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
resultType
TypeThe result type after the operation.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateCast(ShapedQueryExpression, Type)
Translates Cast<TResult>(IQueryable) method over the given source.
protected abstract ShapedQueryExpression? TranslateCast(ShapedQueryExpression source, Type castType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
castType
TypeThe type result is being casted to.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateConcat(ShapedQueryExpression, ShapedQueryExpression)
Translates Concat<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
Parameters
source1
ShapedQueryExpressionThe shaped query on which the operator is applied.
source2
ShapedQueryExpressionThe other source to perform concat.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateContains(ShapedQueryExpression, Expression)
Translates Contains<TSource>(IQueryable<TSource>, TSource) method over the given source.
protected abstract ShapedQueryExpression? TranslateContains(ShapedQueryExpression source, Expression item)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
item
ExpressionThe item to search for.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateCount(ShapedQueryExpression, LambdaExpression?)
Translates Count<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateCount(ShapedQueryExpression source, LambdaExpression? predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateDefaultIfEmpty(ShapedQueryExpression, Expression?)
Translates DefaultIfEmpty<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression? defaultValue)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
defaultValue
ExpressionThe default value to use.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateDistinct(ShapedQueryExpression)
Translates Distinct<TSource>(IQueryable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateDistinct(ShapedQueryExpression source)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateElementAtOrDefault(ShapedQueryExpression, Expression, bool)
Translates ElementAt<TSource>(IQueryable<TSource>, int) method or ElementAtOrDefault<TSource>(IQueryable<TSource>, int) over the given source.
protected abstract ShapedQueryExpression? TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
index
ExpressionThe index of the element.
returnDefault
boolA value indicating whether default should be returned or throw.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateExcept(ShapedQueryExpression, ShapedQueryExpression)
Translates Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
Parameters
source1
ShapedQueryExpressionThe shaped query on which the operator is applied.
source2
ShapedQueryExpressionThe other source to perform except with.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateFirstOrDefault(ShapedQueryExpression, LambdaExpression?, Type, bool)
Translates First<TSource>(IQueryable<TSource>) method or FirstOrDefault<TSource>(IQueryable<TSource>) and their other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateFirstOrDefault(ShapedQueryExpression source, LambdaExpression? predicate, Type returnType, bool returnDefault)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
returnType
TypeThe return type of result.
returnDefault
boolA value indicating whether default should be returned or throw.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateGroupBy(ShapedQueryExpression, LambdaExpression, LambdaExpression?, LambdaExpression?)
Translates GroupBy<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression? elementSelector, LambdaExpression? resultSelector)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
keySelector
LambdaExpressionThe key selector supplied in the call.
elementSelector
LambdaExpressionThe element selector supplied in the call.
resultSelector
LambdaExpressionThe result selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateGroupJoin(ShapedQueryExpression, ShapedQueryExpression, LambdaExpression, LambdaExpression, LambdaExpression)
Translates GroupJoin<TOuter, TInner, TKey, TResult>(IQueryable<TOuter>, IEnumerable<TInner>, Expression<Func<TOuter, TKey>>, Expression<Func<TInner, TKey>>, Expression<Func<TOuter, IEnumerable<TInner>, TResult>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
Parameters
outer
ShapedQueryExpressionThe shaped query on which the operator is applied.
inner
ShapedQueryExpressionThe inner shaped query to perform join with.
outerKeySelector
LambdaExpressionThe key selector for the outer source.
innerKeySelector
LambdaExpressionThe key selector for the inner source.
resultSelector
LambdaExpressionThe result selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateIntersect(ShapedQueryExpression, ShapedQueryExpression)
Translates Intersect<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
Parameters
source1
ShapedQueryExpressionThe shaped query on which the operator is applied.
source2
ShapedQueryExpressionThe other source to perform intersect with.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateJoin(ShapedQueryExpression, ShapedQueryExpression, LambdaExpression, LambdaExpression, LambdaExpression)
Translates Join<TOuter, TInner, TKey, TResult>(IQueryable<TOuter>, IEnumerable<TInner>, Expression<Func<TOuter, TKey>>, Expression<Func<TInner, TKey>>, Expression<Func<TOuter, TInner, TResult>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
Parameters
outer
ShapedQueryExpressionThe shaped query on which the operator is applied.
inner
ShapedQueryExpressionThe inner shaped query to perform join with.
outerKeySelector
LambdaExpressionThe key selector for the outer source.
innerKeySelector
LambdaExpressionThe key selector for the inner source.
resultSelector
LambdaExpressionThe result selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateLastOrDefault(ShapedQueryExpression, LambdaExpression?, Type, bool)
Translates Last<TSource>(IQueryable<TSource>) method or LastOrDefault<TSource>(IQueryable<TSource>) and their other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateLastOrDefault(ShapedQueryExpression source, LambdaExpression? predicate, Type returnType, bool returnDefault)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
returnType
TypeThe return type of result.
returnDefault
boolA value indicating whether default should be returned or throw.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateLeftJoin(ShapedQueryExpression, ShapedQueryExpression, LambdaExpression, LambdaExpression, LambdaExpression)
Translates LeftJoin over the given source.
protected abstract ShapedQueryExpression? TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
Parameters
outer
ShapedQueryExpressionThe shaped query on which the operator is applied.
inner
ShapedQueryExpressionThe inner shaped query to perform join with.
outerKeySelector
LambdaExpressionThe key selector for the outer source.
innerKeySelector
LambdaExpressionThe key selector for the inner source.
resultSelector
LambdaExpressionThe result selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
Remarks
Certain patterns of GroupJoin-DefaultIfEmpty-SelectMany represents a left join in database. We identify such pattern in advance and convert it to join like syntax.
TranslateLongCount(ShapedQueryExpression, LambdaExpression?)
Translates LongCount<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateLongCount(ShapedQueryExpression source, LambdaExpression? predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateMax(ShapedQueryExpression, LambdaExpression?, Type)
Translates Max<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateMax(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
resultType
TypeThe result type after the operation.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateMin(ShapedQueryExpression, LambdaExpression?, Type)
Translates Min<TSource>(IQueryable<TSource>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
resultType
TypeThe result type after the operation.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateOfType(ShapedQueryExpression, Type)
Translates OfType<TResult>(IQueryable) method over the given source.
protected abstract ShapedQueryExpression? TranslateOfType(ShapedQueryExpression source, Type resultType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
resultType
TypeThe type of result which is being filtered with.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateOrderBy(ShapedQueryExpression, LambdaExpression, bool)
Translates OrderBy<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) or OrderByDescending<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
keySelector
LambdaExpressionThe key selector supplied in the call.
ascending
boolA value indicating whether the ordering is ascending or not.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateReverse(ShapedQueryExpression)
Translates Reverse<TSource>(IQueryable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateReverse(ShapedQueryExpression source)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSelect(ShapedQueryExpression, LambdaExpression)
Translates Select<TSource, TResult>(IQueryable<TSource>, Expression<Func<TSource, TResult>>) method over the given source.
protected abstract ShapedQueryExpression TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSelectMany(ShapedQueryExpression, LambdaExpression)
Translates SelectMany<TSource, TResult>(IQueryable<TSource>, Expression<Func<TSource, IEnumerable<TResult>>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSelectMany(ShapedQueryExpression, LambdaExpression, LambdaExpression)
Translates SelectMany<TSource, TCollection, TResult>(IQueryable<TSource>, Expression<Func<TSource, IEnumerable<TCollection>>>, Expression<Func<TSource, TCollection, TResult>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
collectionSelector
LambdaExpressionThe collection selector supplied in the call.
resultSelector
LambdaExpressionThe result selector supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSingleOrDefault(ShapedQueryExpression, LambdaExpression?, Type, bool)
Translates Single<TSource>(IQueryable<TSource>) method or SingleOrDefault<TSource>(IQueryable<TSource>) and their other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateSingleOrDefault(ShapedQueryExpression source, LambdaExpression? predicate, Type returnType, bool returnDefault)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
returnType
TypeThe return type of result.
returnDefault
boolA value indicating whether default should be returned or throw.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSkip(ShapedQueryExpression, Expression)
Translates Skip<TSource>(IQueryable<TSource>, int) method over the given source.
protected abstract ShapedQueryExpression? TranslateSkip(ShapedQueryExpression source, Expression count)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
count
ExpressionThe count supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSkipWhile(ShapedQueryExpression, LambdaExpression)
Translates SkipWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateSubquery(Expression)
Translates the given subquery.
public virtual ShapedQueryExpression? TranslateSubquery(Expression expression)
Parameters
expression
ExpressionThe subquery expression to translate.
Returns
- ShapedQueryExpression
The translation of the given subquery.
TranslateSum(ShapedQueryExpression, LambdaExpression?, Type)
Translates Sum(IQueryable<decimal>) method and other overloads over the given source.
protected abstract ShapedQueryExpression? TranslateSum(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
selector
LambdaExpressionThe selector supplied in the call.
resultType
TypeThe result type after the operation.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateTake(ShapedQueryExpression, Expression)
Translates Take<TSource>(IQueryable<TSource>, int) method over the given source.
protected abstract ShapedQueryExpression? TranslateTake(ShapedQueryExpression source, Expression count)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
count
ExpressionThe count supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateTakeWhile(ShapedQueryExpression, LambdaExpression)
Translates TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateThenBy(ShapedQueryExpression, LambdaExpression, bool)
Translates ThenBy<TSource, TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource, TKey>>) or ThenByDescending<TSource, TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource, TKey>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
keySelector
LambdaExpressionThe key selector supplied in the call.
ascending
boolA value indicating whether the ordering is ascending or not.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateUnion(ShapedQueryExpression, ShapedQueryExpression)
Translates Union<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method over the given source.
protected abstract ShapedQueryExpression? TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
Parameters
source1
ShapedQueryExpressionThe shaped query on which the operator is applied.
source2
ShapedQueryExpressionThe other source to perform union with.
Returns
- ShapedQueryExpression
The shaped query after translation.
TranslateWhere(ShapedQueryExpression, LambdaExpression)
Translates Where<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) method over the given source.
protected abstract ShapedQueryExpression? TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
Parameters
source
ShapedQueryExpressionThe shaped query on which the operator is applied.
predicate
LambdaExpressionThe predicate supplied in the call.
Returns
- ShapedQueryExpression
The shaped query after translation.
VisitExtension(Expression)
protected override Expression VisitExtension(Expression extensionExpression)
Parameters
extensionExpression
Expression
Returns
VisitMethodCall(MethodCallExpression)
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
Parameters
methodCallExpression
MethodCallExpression