Table of Contents

Class SelectExpression

Namespace
Microsoft.EntityFrameworkCore.Query.SqlExpressions
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

An expression that represents a SELECT in a SQL tree.

This type is typically used by database providers (and other extensions). It is generally not used in application code.

public sealed class SelectExpression : TableExpressionBase, IPrintableExpression
Inheritance
SelectExpression
Implements
IPrintableExpression
Inherited Members

Remarks

This class is not publicly constructable. If this is a problem for your application or provider, then please file an issue at github.com/dotnet/efcore.

Properties

GroupBy

The SQL GROUP BY clause for the SELECT.

public IReadOnlyList<SqlExpression> GroupBy { get; }

Property Value

IReadOnlyList<SqlExpression>

Having

The HAVING predicate for the SELECT when GroupBy clause exists.

public SqlExpression? Having { get; }

Property Value

SqlExpression

IsDistinct

A bool value indicating if DISTINCT is applied to projection of this SelectExpression.

public bool IsDistinct { get; }

Property Value

bool

Limit

The limit applied to the number of rows in the result set.

public SqlExpression? Limit { get; }

Property Value

SqlExpression

Offset

The offset to skip rows from the result set.

public SqlExpression? Offset { get; }

Property Value

SqlExpression

Orderings

The list of orderings used to sort the result set.

public IReadOnlyList<OrderingExpression> Orderings { get; }

Property Value

IReadOnlyList<OrderingExpression>

Predicate

The WHERE predicate for the SELECT.

public SqlExpression? Predicate { get; }

Property Value

SqlExpression

Projection

The list of expressions being projected out from the result set.

public IReadOnlyList<ProjectionExpression> Projection { get; }

Property Value

IReadOnlyList<ProjectionExpression>

Tables

The list of tables sources used to generate the result set.

public IReadOnlyList<TableExpressionBase> Tables { get; }

Property Value

IReadOnlyList<TableExpressionBase>

Tags

The list of tags applied to this SelectExpression.

public ISet<string> Tags { get; }

Property Value

ISet<string>

Methods

AddAnnotation(string, object?)

public override TableExpressionBase AddAnnotation(string name, object? value)

Parameters

name string
value object

Returns

TableExpressionBase

AddCrossApply(ShapedQueryExpression, Expression)

Adds the query expression of the given Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to table sources using CROSS APPLY and combine shapers.

public Expression AddCrossApply(ShapedQueryExpression innerSource, Expression outerShaper)

Parameters

innerSource ShapedQueryExpression

A Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to join with.

outerShaper Expression

An expression for outer shaper.

Returns

Expression

An expression which shapes the result of this join.

AddCrossApply(SelectExpression)

Adds the given SelectExpression to table sources using CROSS APPLY.

public void AddCrossApply(SelectExpression innerSelectExpression)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

AddCrossJoin(ShapedQueryExpression, Expression)

Adds the query expression of the given Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to table sources using CROSS JOIN and combine shapers.

public Expression AddCrossJoin(ShapedQueryExpression innerSource, Expression outerShaper)

Parameters

innerSource ShapedQueryExpression

A Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to join with.

outerShaper Expression

An expression for outer shaper.

Returns

Expression

An expression which shapes the result of this join.

AddCrossJoin(SelectExpression)

Adds the given SelectExpression to table sources using CROSS JOIN.

public void AddCrossJoin(SelectExpression innerSelectExpression)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

AddInnerJoin(ShapedQueryExpression, SqlExpression, Expression)

Adds the query expression of the given Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to table sources using INNER JOIN and combine shapers.

public Expression AddInnerJoin(ShapedQueryExpression innerSource, SqlExpression joinPredicate, Expression outerShaper)

Parameters

innerSource ShapedQueryExpression

A Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

outerShaper Expression

An expression for outer shaper.

Returns

Expression

An expression which shapes the result of this join.

AddInnerJoin(SelectExpression, SqlExpression)

Adds the given SelectExpression to table sources using INNER JOIN.

public void AddInnerJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

AddLeftJoin(ShapedQueryExpression, SqlExpression, Expression)

Adds the query expression of the given Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to table sources using LEFT JOIN and combine shapers.

public Expression AddLeftJoin(ShapedQueryExpression innerSource, SqlExpression joinPredicate, Expression outerShaper)

Parameters

innerSource ShapedQueryExpression

A Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

outerShaper Expression

An expression for outer shaper.

Returns

Expression

An expression which shapes the result of this join.

AddLeftJoin(SelectExpression, SqlExpression)

Adds the given SelectExpression to table sources using LEFT JOIN.

public void AddLeftJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

AddOuterApply(ShapedQueryExpression, Expression)

Adds the query expression of the given Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to table sources using OUTER APPLY and combine shapers.

public Expression AddOuterApply(ShapedQueryExpression innerSource, Expression outerShaper)

Parameters

innerSource ShapedQueryExpression

A Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression to join with.

outerShaper Expression

An expression for outer shaper.

Returns

Expression

An expression which shapes the result of this join.

AddOuterApply(SelectExpression)

Adds the given SelectExpression to table sources using OUTER APPLY.

public void AddOuterApply(SelectExpression innerSelectExpression)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

AddToProjection(SqlExpression)

Adds given SqlExpression to the projection.

public int AddToProjection(SqlExpression sqlExpression)

Parameters

sqlExpression SqlExpression

An expression to add.

Returns

int

An int value indicating the index at which the expression was added in the projection list.

AppendOrdering(OrderingExpression)

Appends ordering to the existing orderings of the SelectExpression.

public void AppendOrdering(OrderingExpression orderingExpression)

Parameters

orderingExpression OrderingExpression

An ordering expression to use for ordering.

ApplyDefaultIfEmpty(ISqlExpressionFactory)

public void ApplyDefaultIfEmpty(ISqlExpressionFactory sqlExpressionFactory)

Parameters

sqlExpressionFactory ISqlExpressionFactory

A factory to use for generating required sql expressions.

ApplyDistinct()

Applies DISTINCT operator to the projections of the SelectExpression.

public void ApplyDistinct()

ApplyExcept(SelectExpression, bool)

Applies EXCEPT operation to the SelectExpression.

public void ApplyExcept(SelectExpression source2, bool distinct)

Parameters

source2 SelectExpression

A SelectExpression to perform the operation.

distinct bool

A bool value indicating if resulting table source should remove duplicates.

ApplyGrouping(Expression)

Applies grouping from given key selector.

public void ApplyGrouping(Expression keySelector)

Parameters

keySelector Expression

An key selector expression for the GROUP BY.

ApplyGrouping(Expression, Expression, ISqlExpressionFactory)

Applies grouping from given key selector and generate RelationalGroupByShaperExpression to shape results.

public RelationalGroupByShaperExpression ApplyGrouping(Expression keySelector, Expression shaperExpression, ISqlExpressionFactory sqlExpressionFactory)

Parameters

keySelector Expression

An key selector expression for the GROUP BY.

shaperExpression Expression

The shaper expression for current query.

sqlExpressionFactory ISqlExpressionFactory

The sql expression factory to use.

Returns

RelationalGroupByShaperExpression

A RelationalGroupByShaperExpression which represents the result of the grouping operation.

ApplyIntersect(SelectExpression, bool)

Applies INTERSECT operation to the SelectExpression.

public void ApplyIntersect(SelectExpression source2, bool distinct)

Parameters

source2 SelectExpression

A SelectExpression to perform the operation.

distinct bool

A bool value indicating if resulting table source should remove duplicates.

ApplyLimit(SqlExpression)

Applies limit to the SelectExpression to limit the number of rows returned in the result set.

public void ApplyLimit(SqlExpression sqlExpression)

Parameters

sqlExpression SqlExpression

An expression representing limit row count.

ApplyOffset(SqlExpression)

Applies offset to the SelectExpression to skip the number of rows in the result set.

public void ApplyOffset(SqlExpression sqlExpression)

Parameters

sqlExpression SqlExpression

An expression representing offset row count.

ApplyOrdering(OrderingExpression)

Applies ordering to the SelectExpression. This overwrites any previous ordering specified.

public void ApplyOrdering(OrderingExpression orderingExpression)

Parameters

orderingExpression OrderingExpression

An ordering expression to use for ordering.

ApplyPredicate(SqlExpression)

Applies filter predicate to the SelectExpression.

public void ApplyPredicate(SqlExpression sqlExpression)

Parameters

sqlExpression SqlExpression

An expression to use for filtering.

ApplyProjection()

Adds expressions from projection mapping to projection ignoring the shaper expression. This method should only be used when populating projection in subquery.

public void ApplyProjection()

ApplyProjection(Expression, ResultCardinality, QuerySplittingBehavior)

Adds expressions from projection mapping to projection and generate updated shaper expression for materialization.

public Expression ApplyProjection(Expression shaperExpression, ResultCardinality resultCardinality, QuerySplittingBehavior querySplittingBehavior)

Parameters

shaperExpression Expression

Current shaper expression which will shape results of this select expression.

resultCardinality ResultCardinality

The result cardinality of this query expression.

querySplittingBehavior QuerySplittingBehavior

The query splitting behavior to use when applying projection for nested collections.

Returns

Expression

Returns modified shaper expression to shape results of this select expression.

ApplyTags(ISet<string>)

Applies a given set of tags.

public void ApplyTags(ISet<string> tags)

Parameters

tags ISet<string>

A list of tags to apply.

ApplyUnion(SelectExpression, bool)

Applies UNION operation to the SelectExpression.

public void ApplyUnion(SelectExpression source2, bool distinct)

Parameters

source2 SelectExpression

A SelectExpression to perform the operation.

distinct bool

A bool value indicating if resulting table source should remove duplicates.

ClearOrdering()

Clears existing orderings.

public void ClearOrdering()

Clone()

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

public SelectExpression Clone()

Returns

SelectExpression

CreateWithAnnotations(IEnumerable<IAnnotation>)

protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)

Parameters

annotations IEnumerable<IAnnotation>

Returns

TableExpressionBase

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FindAnnotation(string)

public override IAnnotation? FindAnnotation(string name)

Parameters

name string

Returns

IAnnotation

GenerateOwnedReferenceEntityProjectionExpression(EntityProjectionExpression, INavigation, ISqlExpressionFactory)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

public EntityShaperExpression GenerateOwnedReferenceEntityProjectionExpression(EntityProjectionExpression principalEntityProjection, INavigation navigation, ISqlExpressionFactory sqlExpressionFactory)

Parameters

principalEntityProjection EntityProjectionExpression
navigation INavigation
sqlExpressionFactory ISqlExpressionFactory

Returns

EntityShaperExpression

GetAnnotations()

public override IEnumerable<IAnnotation> GetAnnotations()

Returns

IEnumerable<IAnnotation>

GetHashCode()

public override int GetHashCode()

Returns

int

GetProjection(ProjectionBindingExpression)

Gets the projection mapped to the given Microsoft.EntityFrameworkCore.Query.ProjectionBindingExpression.

public Expression GetProjection(ProjectionBindingExpression projectionBindingExpression)

Parameters

projectionBindingExpression ProjectionBindingExpression

A projection binding to search.

Returns

Expression

The mapped projection for given projection binding.

IsNonComposedFromSql()

Checks whether this SelectExpression represents a FromSqlExpression which is not composed upon.

public bool IsNonComposedFromSql()

Returns

bool

A bool value indicating a non-composed FromSqlExpression.

PrepareForAggregate()

Prepares the SelectExpression to apply aggregate operation over it.

public void PrepareForAggregate()

Print(ExpressionPrinter)

protected override void Print(ExpressionPrinter expressionPrinter)

Parameters

expressionPrinter ExpressionPrinter

Prune()

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

public SelectExpression Prune()

Returns

SelectExpression

PushdownIntoSubquery()

Pushes down the SelectExpression into a subquery.

public void PushdownIntoSubquery()

ReplaceProjection(IReadOnlyDictionary<ProjectionMember, Expression>)

Replaces current projection mapping with a new one to change what is being projected out from this SelectExpression.

public void ReplaceProjection(IReadOnlyDictionary<ProjectionMember, Expression> projectionMapping)

Parameters

projectionMapping IReadOnlyDictionary<ProjectionMember, Expression>

A new projection mapping.

ReplaceProjection(IReadOnlyList<Expression>)

Replaces current projection mapping with a new one to change what is being projected out from this SelectExpression.

public void ReplaceProjection(IReadOnlyList<Expression> clientProjections)

Parameters

clientProjections IReadOnlyList<Expression>

A new projection mapping.

ReverseOrderings()

Reverses the existing orderings on the SelectExpression.

public void ReverseOrderings()

Update(IReadOnlyList<ProjectionExpression>, IReadOnlyList<TableExpressionBase>, SqlExpression?, IReadOnlyList<SqlExpression>, SqlExpression?, IReadOnlyList<OrderingExpression>, SqlExpression?, SqlExpression?)

Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will return this expression.

public SelectExpression Update(IReadOnlyList<ProjectionExpression> projections, IReadOnlyList<TableExpressionBase> tables, SqlExpression? predicate, IReadOnlyList<SqlExpression> groupBy, SqlExpression? having, IReadOnlyList<OrderingExpression> orderings, SqlExpression? limit, SqlExpression? offset)

Parameters

projections IReadOnlyList<ProjectionExpression>

The Projection property of the result.

tables IReadOnlyList<TableExpressionBase>

The Tables property of the result.

predicate SqlExpression

The Predicate property of the result.

groupBy IReadOnlyList<SqlExpression>

The GroupBy property of the result.

having SqlExpression

The Having property of the result.

orderings IReadOnlyList<OrderingExpression>

The Orderings property of the result.

limit SqlExpression

The Limit property of the result.

offset SqlExpression

The Offset property of the result.

Returns

SelectExpression

This expression if no children changed, or an expression with the updated children.

VisitChildren(ExpressionVisitor)

protected override Expression VisitChildren(ExpressionVisitor visitor)

Parameters

visitor ExpressionVisitor

Returns

Expression