Table of Contents

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

Constructors

QueryableMethodTranslatingExpressionVisitor(QueryableMethodTranslatingExpressionVisitorDependencies, QueryCompilationContext, bool)

Creates a new instance of the QueryableMethodTranslatingExpressionVisitor class.

protected QueryableMethodTranslatingExpressionVisitor(QueryableMethodTranslatingExpressionVisitorDependencies dependencies, QueryCompilationContext queryCompilationContext, bool subquery)

Parameters

dependencies QueryableMethodTranslatingExpressionVisitorDependencies

Parameter object containing dependencies for this class.

queryCompilationContext QueryCompilationContext

The query compilation context object to use.

subquery bool

A bool value indicating whether it is for a subquery translation.

Properties

Dependencies

Dependencies for this service.

protected virtual QueryableMethodTranslatingExpressionVisitorDependencies Dependencies { get; }

Property Value

QueryableMethodTranslatingExpressionVisitorDependencies

QueryCompilationContext

The query compilation context object for current compilation.

protected virtual QueryCompilationContext QueryCompilationContext { get; }

Property Value

QueryCompilationContext

TranslationErrorDetails

Detailed information about errors encountered during translation.

public virtual string? TranslationErrorDetails { get; }

Property Value

string

Methods

AddTranslationErrorDetails(string)

Adds detailed information about errors encountered during translation.

protected virtual void AddTranslationErrorDetails(string details)

Parameters

details string

Error encountered during translation.

CreateShapedQueryExpression(IEntityType)

Creates a ShapedQueryExpression for the given entity type.

protected abstract ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType)

Parameters

entityType IEntityType

The 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 Expression

The 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 Expression

An expression to translate.

Returns

Expression

A SQL translation of the given expression.

TranslateAll(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

resultType Type

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

castType Type

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

source2 ShapedQueryExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

item Expression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

defaultValue Expression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateElementAtOrDefault(ShapedQueryExpression, Expression, bool)

protected abstract ShapedQueryExpression? TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

index Expression

The index of the element.

returnDefault bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

source2 ShapedQueryExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The predicate supplied in the call.

returnType Type

The return type of result.

returnDefault bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

keySelector LambdaExpression

The key selector supplied in the call.

elementSelector LambdaExpression

The element selector supplied in the call.

resultSelector LambdaExpression

The result selector supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateGroupJoin(ShapedQueryExpression, ShapedQueryExpression, LambdaExpression, LambdaExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)

Parameters

outer ShapedQueryExpression

The shaped query on which the operator is applied.

inner ShapedQueryExpression

The inner shaped query to perform join with.

outerKeySelector LambdaExpression

The key selector for the outer source.

innerKeySelector LambdaExpression

The key selector for the inner source.

resultSelector LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

source2 ShapedQueryExpression

The other source to perform intersect with.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateJoin(ShapedQueryExpression, ShapedQueryExpression, LambdaExpression, LambdaExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)

Parameters

outer ShapedQueryExpression

The shaped query on which the operator is applied.

inner ShapedQueryExpression

The inner shaped query to perform join with.

outerKeySelector LambdaExpression

The key selector for the outer source.

innerKeySelector LambdaExpression

The key selector for the inner source.

resultSelector LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The predicate supplied in the call.

returnType Type

The return type of result.

returnDefault bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

inner ShapedQueryExpression

The inner shaped query to perform join with.

outerKeySelector LambdaExpression

The key selector for the outer source.

innerKeySelector LambdaExpression

The key selector for the inner source.

resultSelector LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

resultType Type

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

resultType Type

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

resultType Type

The type of result which is being filtered with.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateOrderBy(ShapedQueryExpression, LambdaExpression, bool)

protected abstract ShapedQueryExpression? TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

keySelector LambdaExpression

The key selector supplied in the call.

ascending bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateSelect(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateSelectMany(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateSelectMany(ShapedQueryExpression, LambdaExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

collectionSelector LambdaExpression

The collection selector supplied in the call.

resultSelector LambdaExpression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The predicate supplied in the call.

returnType Type

The return type of result.

returnDefault bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

count Expression

The count supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateSkipWhile(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The 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 Expression

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

selector LambdaExpression

The selector supplied in the call.

resultType Type

The 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 ShapedQueryExpression

The shaped query on which the operator is applied.

count Expression

The count supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateTakeWhile(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The predicate supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateThenBy(ShapedQueryExpression, LambdaExpression, bool)

protected abstract ShapedQueryExpression? TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

keySelector LambdaExpression

The key selector supplied in the call.

ascending bool

A 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 ShapedQueryExpression

The shaped query on which the operator is applied.

source2 ShapedQueryExpression

The other source to perform union with.

Returns

ShapedQueryExpression

The shaped query after translation.

TranslateWhere(ShapedQueryExpression, LambdaExpression)

protected abstract ShapedQueryExpression? TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)

Parameters

source ShapedQueryExpression

The shaped query on which the operator is applied.

predicate LambdaExpression

The predicate supplied in the call.

Returns

ShapedQueryExpression

The shaped query after translation.

VisitExtension(Expression)

protected override Expression VisitExtension(Expression extensionExpression)

Parameters

extensionExpression Expression

Returns

Expression

VisitMethodCall(MethodCallExpression)

protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)

Parameters

methodCallExpression MethodCallExpression

Returns

Expression