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.

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

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

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

AddCollectionProjection(ShapedQueryExpression, INavigationBase, Type)

Adds a collection to the projection of the SelectExpression.

public CollectionShaperExpression AddCollectionProjection(ShapedQueryExpression shapedQueryExpression, INavigationBase navigation, Type elementType)

Parameters

shapedQueryExpression ShapedQueryExpression

A shaped query expression for the subquery producing collection result.

navigation INavigationBase

A navigation associated with this collection, if any.

elementType Type

The type of the element in the collection.

Returns

CollectionShaperExpression

A Microsoft.EntityFrameworkCore.Query.CollectionShaperExpression which represents shaping of this collection.

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.

AddCrossApply(SelectExpression, Type)

Adds the given SelectExpression to table sources using CROSS APPLY.

[Obsolete("Use the other overloads.")]
public void AddCrossApply(SelectExpression innerSelectExpression, Type transparentIdentifierType)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

transparentIdentifierType Type

The type of the result generated after performing the join.

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.

AddCrossJoin(SelectExpression, Type)

Adds the given SelectExpression to table sources using CROSS JOIN.

[Obsolete("Use the other overloads.")]
public void AddCrossJoin(SelectExpression innerSelectExpression, Type transparentIdentifierType)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

transparentIdentifierType Type

The type of the result generated after performing the join.

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.

AddInnerJoin(SelectExpression, SqlExpression, Type)

Adds the given SelectExpression to table sources using INNER JOIN.

[Obsolete("Use the other overloads.")]
public void AddInnerJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate, Type transparentIdentifierType)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

transparentIdentifierType Type

The type of the result generated after performing 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.

AddLeftJoin(SelectExpression, SqlExpression, Type)

Adds the given SelectExpression to table sources using LEFT JOIN.

[Obsolete("Use the other overloads.")]
public void AddLeftJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate, Type transparentIdentifierType)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

joinPredicate SqlExpression

A predicate to use for the join.

transparentIdentifierType Type

The type of the result generated after performing 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.

AddOuterApply(SelectExpression, Type)

Adds the given SelectExpression to table sources using OUTER APPLY.

[Obsolete("Use the other overloads.")]
public void AddOuterApply(SelectExpression innerSelectExpression, Type transparentIdentifierType)

Parameters

innerSelectExpression SelectExpression

A SelectExpression to join with.

transparentIdentifierType Type

The type of the result generated after performing the join.

AddSingleProjection(ShapedQueryExpression)

Adds a non-scalar single result to the projection of the SelectExpression.

public Expression AddSingleProjection(ShapedQueryExpression shapedQueryExpression)

Parameters

shapedQueryExpression ShapedQueryExpression

A shaped query expression for the subquery producing single non-scalar result.

Returns

Expression

A shaper expression to shape the result of this projection.

AddToProjection(EntityProjectionExpression)

Adds given EntityProjectionExpression to the projection.

public IDictionary<IProperty, int> AddToProjection(EntityProjectionExpression entityProjection)

Parameters

entityProjection EntityProjectionExpression

An entity projection to add.

Returns

IDictionary<IProperty, int>

A dictionary of Microsoft.EntityFrameworkCore.Metadata.IProperty to int indicating properties and their corresponding indexes in the projection list.

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.

ApplyCollectionJoin(int, int, Expression, INavigationBase, Type, bool)

Applies previously added collection projection.

public Expression ApplyCollectionJoin(int collectionIndex, int collectionId, Expression innerShaper, INavigationBase navigation, Type elementType, bool splitQuery = false)

Parameters

collectionIndex int

An int value specifing which collection from pending collection to apply.

collectionId int

An int value of unique collection id associated with this collection projection.

innerShaper Expression

A shaper expression to use for shaping the elements of this collection.

navigation INavigationBase

A navigation associated with this collection, if any.

elementType Type

The type of the element in the collection.

splitQuery bool

A value indicating whether the collection query would be run with a different DbCommand.

Returns

Expression

An expression which represents shaping of this collection.

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.

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 expression)

Parameters

expression SqlExpression

An expression to use for filtering.

ApplyProjection()

Adds expressions from projection mapping to projection if not done already.

public void ApplyProjection()

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()

ClearProjection()

Clears all existing projections.

public void ClearProjection()

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

GetMappedProjection(ProjectionMember)

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

public Expression GetMappedProjection(ProjectionMember projectionMember)

Parameters

projectionMember ProjectionMember

A projection member to search in the mapping.

Returns

Expression

The mapped projection for given projection member.

IsNonComposedFromSql()

Checks whether this SelectExpression representes 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 IDictionary<SqlExpression, ColumnExpression> PushdownIntoSubquery()

Returns

IDictionary<SqlExpression, ColumnExpression>

A mapping of projections before pushdown to ColumnExpressions after pushdown.

ReplaceProjectionMapping(IDictionary<ProjectionMember, Expression>)

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

public void ReplaceProjectionMapping(IDictionary<ProjectionMember, Expression> projectionMapping)

Parameters

projectionMapping IDictionary<ProjectionMember, Expression>

A new projection mapping.

ReverseOrderings()

Reverses the existing orderings on the SelectExpression.

public void ReverseOrderings()

Update(List<ProjectionExpression>, List<TableExpressionBase>, SqlExpression, List<SqlExpression>, SqlExpression, List<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(List<ProjectionExpression> projections, List<TableExpressionBase> tables, SqlExpression predicate, List<SqlExpression> groupBy, SqlExpression having, List<OrderingExpression> orderings, SqlExpression limit, SqlExpression offset)

Parameters

projections List<ProjectionExpression>

The Projection property of the result.

tables List<TableExpressionBase>

The Tables property of the result.

predicate SqlExpression

The Predicate property of the result.

groupBy List<SqlExpression>

The GroupBy property of the result.

having SqlExpression

The Having property of the result.

orderings List<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.

Update(List<ProjectionExpression>, List<TableExpressionBase>, SqlExpression, List<SqlExpression>, SqlExpression, List<OrderingExpression>, SqlExpression, SqlExpression, bool, string)

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.

[Obsolete("Use the overload which does not require distinct & alias parameter.")]
public SelectExpression Update(List<ProjectionExpression> projections, List<TableExpressionBase> tables, SqlExpression predicate, List<SqlExpression> groupBy, SqlExpression having, List<OrderingExpression> orderings, SqlExpression limit, SqlExpression offset, bool distinct, string alias)

Parameters

projections List<ProjectionExpression>

The Projection property of the result.

tables List<TableExpressionBase>

The Tables property of the result.

predicate SqlExpression

The Predicate property of the result.

groupBy List<SqlExpression>

The GroupBy property of the result.

having SqlExpression

The Having property of the result.

orderings List<OrderingExpression>

The Orderings property of the result.

limit SqlExpression

The Limit property of the result.

offset SqlExpression

The Offset property of the result.

distinct bool

The IsDistinct property of the result.

alias string

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