Table of Contents

Interface ISqlExpressionFactory

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

A factory for creating SqlExpression instances.

public interface ISqlExpressionFactory

Remarks

The service lifetime is Scoped. This means that each Microsoft.EntityFrameworkCore.DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

Methods

Add(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents an addition.

SqlBinaryExpression Add(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL addition.

And(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a bitwise AND operation.

SqlBinaryExpression And(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL bitwise AND operation.

AndAlso(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a logical AND operation.

SqlBinaryExpression AndAlso(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL AND operation.

ApplyDefaultTypeMapping(SqlExpression?)

Applies default type mapping to given SqlExpression.

SqlExpression? ApplyDefaultTypeMapping(SqlExpression? sqlExpression)

Parameters

sqlExpression SqlExpression

A SQL Expression to apply default type mapping.

Returns

SqlExpression

A SQL expression with default type mapping applied.

ApplyTypeMapping(SqlExpression?, RelationalTypeMapping?)

Applies type mapping to the given SqlExpression.

SqlExpression? ApplyTypeMapping(SqlExpression? sqlExpression, RelationalTypeMapping? typeMapping)

Parameters

sqlExpression SqlExpression

A SQL expression to apply type mapping.

typeMapping RelationalTypeMapping

A type mapping to apply.

Returns

SqlExpression

A SQL expression with given type mapping applied.

Case(SqlExpression, IReadOnlyList<CaseWhenClause>, SqlExpression?)

Creates a new CaseExpression which represent a CASE statement in a SQL tree.

CaseExpression Case(SqlExpression operand, IReadOnlyList<CaseWhenClause> whenClauses, SqlExpression? elseResult)

Parameters

operand SqlExpression

An expression to compare with Test in whenClauses.

whenClauses IReadOnlyList<CaseWhenClause>

A list of CaseWhenClause to compare and get result from.

elseResult SqlExpression

A value to return if no whenClauses matches, if any.

Returns

CaseExpression

An expression representing a CASE statement in a SQL tree.

Case(IReadOnlyList<CaseWhenClause>, SqlExpression?)

Creates a new CaseExpression which represent a CASE statement in a SQL tree.

CaseExpression Case(IReadOnlyList<CaseWhenClause> whenClauses, SqlExpression? elseResult)

Parameters

whenClauses IReadOnlyList<CaseWhenClause>

A list of CaseWhenClause to evaluate condition and get result from.

elseResult SqlExpression

A value to return if no whenClauses matches, if any.

Returns

CaseExpression

An expression representing a CASE statement in a SQL tree.

Coalesce(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlFunctionExpression which represents a COALESCE operation.

SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlFunctionExpression

An expression representing a SQL COALESCE operation.

Constant(object?, RelationalTypeMapping?)

Creates a new SqlConstantExpression which represents a constant in a SQL tree.

SqlConstantExpression Constant(object? value, RelationalTypeMapping? typeMapping = null)

Parameters

value object

A value.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlConstantExpression

An expression representing a constant in a SQL tree.

Constant(object?, Type, RelationalTypeMapping?)

Creates a new SqlConstantExpression which represents a constant in a SQL tree.

SqlConstantExpression Constant(object? value, Type type, RelationalTypeMapping? typeMapping = null)

Parameters

value object

A value.

type Type

The type for the constant. Useful when value is null.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlConstantExpression

An expression representing a constant in a SQL tree.

Convert(SqlExpression, Type, RelationalTypeMapping?)

Creates a new SqlUnaryExpression which represent casting a SQL expression to different type.

SqlUnaryExpression Convert(SqlExpression operand, Type type, RelationalTypeMapping? typeMapping = null)

Parameters

operand SqlExpression

A SqlExpression to cast.

type Type

The return type of the expression after cast.

typeMapping RelationalTypeMapping

A relational type mapping to use for conversion.

Returns

SqlUnaryExpression

An expression representing cast operation in a SQL tree.

Divide(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a division.

SqlBinaryExpression Divide(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL division.

Equal(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents an equality comparison.

SqlBinaryExpression Equal(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL equality comparison.

Exists(SelectExpression, bool)

Creates a new ExistsExpression which represents an EXISTS operation in a SQL tree.

ExistsExpression Exists(SelectExpression subquery, bool negated)

Parameters

subquery SelectExpression

A subquery to check existence of.

negated bool

A value indicating if the existence check is negated.

Returns

ExistsExpression

An expression representing an EXISTS operation in a SQL tree.

Fragment(string)

Creates a new SqlFragmentExpression which represents a SQL token.

SqlFragmentExpression Fragment(string sql)

Parameters

sql string

A string token to print in SQL tree.

Returns

SqlFragmentExpression

An expression representing a SQL token.

Function(SqlExpression, string, IEnumerable<SqlExpression>, bool, bool, IEnumerable<bool>, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a function call in a SQL tree.

SqlFunctionExpression Function(SqlExpression instance, string name, IEnumerable<SqlExpression> arguments, bool nullable, bool instancePropagatesNullability, IEnumerable<bool> argumentsPropagateNullability, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

instance SqlExpression

An expression on which the function is applied.

name string

The name of the function.

arguments IEnumerable<SqlExpression>

The arguments of the function.

nullable bool

A bool value indicating whether this function can return null.

instancePropagatesNullability bool

A value indicating if instance propagates null to result.

argumentsPropagateNullability IEnumerable<bool>

A list of bool values indicating whether individual arguments propagate null to result.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

Function(string, IEnumerable<SqlExpression>, bool, IEnumerable<bool>, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a function call in a SQL tree.

SqlFunctionExpression Function(string name, IEnumerable<SqlExpression> arguments, bool nullable, IEnumerable<bool> argumentsPropagateNullability, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

name string

The name of the function.

arguments IEnumerable<SqlExpression>

The arguments of the function.

nullable bool

A bool value indicating whether this function can return null.

argumentsPropagateNullability IEnumerable<bool>

A list of bool values indicating whether individual arguments propagate null to result.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

Function(string?, string, IEnumerable<SqlExpression>, bool, IEnumerable<bool>, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a function call in a SQL tree.

SqlFunctionExpression Function(string? schema, string name, IEnumerable<SqlExpression> arguments, bool nullable, IEnumerable<bool> argumentsPropagateNullability, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

schema string

The schema in which the function is defined.

name string

The name of the function.

arguments IEnumerable<SqlExpression>

The arguments of the function.

nullable bool

A bool value indicating whether this function can return null.

argumentsPropagateNullability IEnumerable<bool>

A list of bool values indicating whether individual arguments propagate null to result.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

GreaterThan(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a greater than comparison.

SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL greater than comparison.

GreaterThanOrEqual(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a greater than or equal comparison.

SqlBinaryExpression GreaterThanOrEqual(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL greater than or equal comparison.

In(SqlExpression, SelectExpression, bool)

Creates a new InExpression which represents an IN operation in a SQL tree.

InExpression In(SqlExpression item, SelectExpression subquery, bool negated)

Parameters

item SqlExpression

An item to look into values.

subquery SelectExpression

A subquery in which item is searched.

negated bool

A value indicating if the item should be present in the values or absent.

Returns

InExpression

An expression representing an IN operation in a SQL tree.

In(SqlExpression, SqlExpression, bool)

Creates a new InExpression which represents an IN operation in a SQL tree.

InExpression In(SqlExpression item, SqlExpression values, bool negated)

Parameters

item SqlExpression

An item to look into values.

values SqlExpression

A list of values in which item is searched.

negated bool

A value indicating if the item should be present in the values or absent.

Returns

InExpression

An expression representing an IN operation in a SQL tree.

IsNotNull(SqlExpression)

Creates a new SqlUnaryExpression which represent inequality to null.

SqlUnaryExpression IsNotNull(SqlExpression operand)

Parameters

operand SqlExpression

A SqlExpression to compare to non null.

Returns

SqlUnaryExpression

An expression representing IS NOT NULL construct in a SQL tree.

IsNull(SqlExpression)

Creates a new SqlUnaryExpression which represent equality to null.

SqlUnaryExpression IsNull(SqlExpression operand)

Parameters

operand SqlExpression

A SqlExpression to compare to null.

Returns

SqlUnaryExpression

An expression representing IS NULL construct in a SQL tree.

LessThan(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a less than comparison.

SqlBinaryExpression LessThan(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL less than comparison.

LessThanOrEqual(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a less than or equal comparison.

SqlBinaryExpression LessThanOrEqual(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL less than or equal comparison.

Like(SqlExpression, SqlExpression, SqlExpression?)

Creates a new InExpression which represents a LIKE in a SQL tree.

LikeExpression Like(SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar = null)

Parameters

match SqlExpression

An expression on which LIKE is applied.

pattern SqlExpression

A pattern to search.

escapeChar SqlExpression

An optional escape character to use in LIKE.

Returns

LikeExpression

An expression representing a LIKE in a SQL tree.

MakeBinary(ExpressionType, SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a new SqlBinaryExpression with the given arguments.

SqlBinaryExpression? MakeBinary(ExpressionType operatorType, SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping)

Parameters

operatorType ExpressionType

An ExpressionType representing SQL unary operator.

left SqlExpression

The left operand of binary operation.

right SqlExpression

The right operand of binary operation.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

A SqlBinaryExpression with the given arguments.

MakeUnary(ExpressionType, SqlExpression, Type, RelationalTypeMapping?)

Creates a new SqlUnaryExpression with the given arguments.

SqlUnaryExpression? MakeUnary(ExpressionType operatorType, SqlExpression operand, Type type, RelationalTypeMapping? typeMapping = null)

Parameters

operatorType ExpressionType

An ExpressionType representing SQL unary operator.

operand SqlExpression

A SqlExpression to apply unary operator on.

type Type

The type of the created expression.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlUnaryExpression

A SqlUnaryExpression with the given arguments.

Modulo(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a modulo operation.

SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL modulo operation.

Multiply(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a multiplication.

SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL multiplication.

Negate(SqlExpression)

Creates a new SqlUnaryExpression which represent a negation operation in a SQL tree.

SqlUnaryExpression Negate(SqlExpression operand)

Parameters

operand SqlExpression

A SqlExpression to apply NOT on.

Returns

SqlUnaryExpression

An expression representing a negation operation in a SQL tree.

NiladicFunction(SqlExpression, string, bool, bool, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a niladic function call in a SQL tree.

SqlFunctionExpression NiladicFunction(SqlExpression instance, string name, bool nullable, bool instancePropagatesNullability, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

instance SqlExpression

An expression on which the function is applied.

name string

The name of the function.

nullable bool

A bool value indicating whether this function can return null.

instancePropagatesNullability bool

A value indicating if instance propagates null to result.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

NiladicFunction(string, bool, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a niladic function call in a SQL tree.

SqlFunctionExpression NiladicFunction(string name, bool nullable, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

name string

The name of the function.

nullable bool

A bool value indicating whether this function can return null.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

NiladicFunction(string, string, bool, Type, RelationalTypeMapping?)

Creates a new SqlFunctionExpression which represents a niladic function call in a SQL tree.

SqlFunctionExpression NiladicFunction(string schema, string name, bool nullable, Type returnType, RelationalTypeMapping? typeMapping = null)

Parameters

schema string

The schema in which the function is defined.

name string

The name of the function.

nullable bool

A bool value indicating whether this function can return null.

returnType Type

The Type of the expression.

typeMapping RelationalTypeMapping

The RelationalTypeMapping associated with the expression.

Returns

SqlFunctionExpression

An expression representing a function call in a SQL tree.

Not(SqlExpression)

Creates a new SqlUnaryExpression which represent a NOT operation in a SQL tree.

SqlUnaryExpression Not(SqlExpression operand)

Parameters

operand SqlExpression

A SqlExpression to apply NOT on.

Returns

SqlUnaryExpression

An expression representing a NOT operation in a SQL tree.

NotEqual(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents an inequality comparison.

SqlBinaryExpression NotEqual(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL inequality comparison.

Or(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a bitwise OR operation.

SqlBinaryExpression Or(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL bitwise OR operation.

OrElse(SqlExpression, SqlExpression)

Creates a SqlBinaryExpression which represents a logical OR operation.

SqlBinaryExpression OrElse(SqlExpression left, SqlExpression right)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

Returns

SqlBinaryExpression

An expression representing a SQL OR operation.

Select(IEntityType)

Creates a new SelectExpression which represents a SELECT in a SQL tree projecting an entity type from a table source created using default mapping in the model.

SelectExpression Select(IEntityType entityType)

Parameters

entityType IEntityType

An entity type to project.

Returns

SelectExpression

An expression representing a SELECT in a SQL tree.

Select(IEntityType, TableExpressionBase)

Creates a new SelectExpression which represents a SELECT in a SQL tree projecting an entity type from a table source.

SelectExpression Select(IEntityType entityType, TableExpressionBase tableExpressionBase)

Parameters

entityType IEntityType

An entity type to project.

tableExpressionBase TableExpressionBase

A table source to project from.

Returns

SelectExpression

An expression representing a SELECT in a SQL tree.

Select(SqlExpression?)

Creates a new SelectExpression which represents a SELECT in a SQL tree projecting a SqlExpression or 1 from no table and without any composition.

SelectExpression Select(SqlExpression? projection)

Parameters

projection SqlExpression

A SqlExpression to project.

Returns

SelectExpression

An expression representing a SELECT in a SQL tree.

Subtract(SqlExpression, SqlExpression, RelationalTypeMapping?)

Creates a SqlBinaryExpression which represents a subtraction.

SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)

Parameters

left SqlExpression

The left operand.

right SqlExpression

The right operand.

typeMapping RelationalTypeMapping

A type mapping to be assigned to the created expression.

Returns

SqlBinaryExpression

An expression representing a SQL subtraction.