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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
sqlExpressionSqlExpressionA 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
sqlExpressionSqlExpressionA SQL expression to apply type mapping.
typeMappingRelationalTypeMappingA 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
operandSqlExpressionAn expression to compare with Test in
whenClauses.whenClausesIReadOnlyList<CaseWhenClause>A list of CaseWhenClause to compare and get result from.
elseResultSqlExpressionA value to return if no
whenClausesmatches, 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
whenClausesIReadOnlyList<CaseWhenClause>A list of CaseWhenClause to evaluate condition and get result from.
elseResultSqlExpressionA value to return if no
whenClausesmatches, 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
valueobjectA value.
typeMappingRelationalTypeMappingThe 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
valueobjectA value.
typeTypeThe type for the constant. Useful when value is null.
typeMappingRelationalTypeMappingThe 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
operandSqlExpressionA SqlExpression to cast.
typeTypeThe return type of the expression after cast.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
subquerySelectExpressionA subquery to check existence of.
negatedboolA 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
sqlstringA 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
instanceSqlExpressionAn expression on which the function is applied.
namestringThe name of the function.
argumentsIEnumerable<SqlExpression>The arguments of the function.
nullableboolA bool value indicating whether this function can return null.
instancePropagatesNullabilityboolA value indicating if instance propagates null to result.
argumentsPropagateNullabilityIEnumerable<bool>A list of bool values indicating whether individual arguments propagate null to result.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
namestringThe name of the function.
argumentsIEnumerable<SqlExpression>The arguments of the function.
nullableboolA bool value indicating whether this function can return null.
argumentsPropagateNullabilityIEnumerable<bool>A list of bool values indicating whether individual arguments propagate null to result.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
schemastringThe schema in which the function is defined.
namestringThe name of the function.
argumentsIEnumerable<SqlExpression>The arguments of the function.
nullableboolA bool value indicating whether this function can return null.
argumentsPropagateNullabilityIEnumerable<bool>A list of bool values indicating whether individual arguments propagate null to result.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
itemSqlExpressionAn item to look into values.
subquerySelectExpressionA subquery in which item is searched.
negatedboolA 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
itemSqlExpressionAn item to look into values.
valuesSqlExpressionA list of values in which item is searched.
negatedboolA 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
operandSqlExpressionA 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
operandSqlExpressionA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
matchSqlExpressionAn expression on which LIKE is applied.
patternSqlExpressionA pattern to search.
escapeCharSqlExpressionAn 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
operatorTypeExpressionTypeAn ExpressionType representing SQL unary operator.
leftSqlExpressionThe left operand of binary operation.
rightSqlExpressionThe right operand of binary operation.
typeMappingRelationalTypeMappingA 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
operatorTypeExpressionTypeAn ExpressionType representing SQL unary operator.
operandSqlExpressionA SqlExpression to apply unary operator on.
typeTypeThe type of the created expression.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
operandSqlExpressionA 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
instanceSqlExpressionAn expression on which the function is applied.
namestringThe name of the function.
nullableboolA bool value indicating whether this function can return null.
instancePropagatesNullabilityboolA value indicating if instance propagates null to result.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
namestringThe name of the function.
nullableboolA bool value indicating whether this function can return null.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
schemastringThe schema in which the function is defined.
namestringThe name of the function.
nullableboolA bool value indicating whether this function can return null.
returnTypeTypeThe Type of the expression.
typeMappingRelationalTypeMappingThe 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
operandSqlExpressionA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe 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
entityTypeIEntityTypeAn 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
entityTypeIEntityTypeAn entity type to project.
tableExpressionBaseTableExpressionBaseA 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
projectionSqlExpressionA 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
leftSqlExpressionThe left operand.
rightSqlExpressionThe right operand.
typeMappingRelationalTypeMappingA type mapping to be assigned to the created expression.
Returns
- SqlBinaryExpression
An expression representing a SQL subtraction.