Class Sql.ExpressionAttribute
- Namespace
- LinqToDB
- Assembly
- linq2db.dll
An Attribute that allows custom Expressions to be defined for a Method used within a Linq Expression.
[Serializable]
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property, AllowMultiple = true, Inherited = false)]
public class Sql.ExpressionAttribute : MappingAttribute, _Attribute
- Inheritance
-
Sql.ExpressionAttribute
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ExpressionAttribute(string?)
Creates an Expression that will be used in SQL, in place of the method call decorated by this attribute.
public ExpressionAttribute(string? expression)
Parameters
expression
stringThe SQL expression. Use {0},{1}... for parameters given to the method call.
ExpressionAttribute(string, params int[])
Creates an Expression that will be used in SQL, in place of the method call decorated by this attribute.
public ExpressionAttribute(string expression, params int[] argIndices)
Parameters
expression
stringThe SQL expression. Use {0},{1}... for parameters given to the method call.
argIndices
int[]Used for setting the order of the method arguments being passed into the function.
ExpressionAttribute(string, string)
Creates an Expression that will be used in SQL, for the ProviderName specified, in place of the method call decorated by this attribute.
public ExpressionAttribute(string configuration, string expression)
Parameters
configuration
stringThe Database configuration for which this Expression will be used.
expression
stringThe SQL expression. Use {0},{1}... for parameters given to the method call.
ExpressionAttribute(string, string, params int[])
Creates an Expression that will be used in SQL, for the ProviderName specified, in place of the method call decorated by this attribute.
public ExpressionAttribute(string configuration, string expression, params int[] argIndices)
Parameters
configuration
stringThe Database configuration for which this Expression will be used.
expression
stringThe SQL expression. Use {0},{1}... for parameters given to the method call.
argIndices
int[]Used for setting the order of the method arguments being passed into the function.
Fields
UnknownExpression
public static readonly SqlExpression UnknownExpression
Field Value
Properties
ArgIndices
The order of Arguments to be passed into the function from the method call.
public int[]? ArgIndices { get; set; }
Property Value
- int[]
CanBeNull
If true
, result can be null
public bool CanBeNull { get; set; }
Property Value
ExpectExpression
Used internally by Sql.ExtensionAttribute.
public bool ExpectExpression { get; set; }
Property Value
Expression
The expression to be used in building the SQL.
public string? Expression { get; set; }
Property Value
IgnoreGenericParameters
if true
, do not generate generic parameters.
public bool IgnoreGenericParameters { get; set; }
Property Value
InlineParameters
If true
inline all parameters passed into the expression.
public bool InlineParameters { get; set; }
Property Value
IsAggregate
If true
, this expression represents an aggregate result
Examples would be SUM(),COUNT().
public bool IsAggregate { get; set; }
Property Value
IsNullable
Used to determine whether the return type should be treated as something that can be null If CanBeNull is not explicitly set.
Default is Undefined,
which will be treated as true
public Sql.IsNullableType IsNullable { get; set; }
Property Value
IsPredicate
If true
the expression is treated as a Predicate
And when used in a Where clause will not have
an added comparison to 'true' in the database.
public bool IsPredicate { get; set; }
Property Value
IsPure
If true
, it notifies SQL Optimizer that expression returns same result if the same values/parameters are used. It gives optimizer additional information how to simplify query.
For example ORDER BY PureFunction("Str") can be removed because PureFunction function uses constant value.
public bool IsPure { get; set; }
Property Value
IsWindowFunction
If true
, this expression represents a Window Function
Examples would be SUM() OVER(), COUNT() OVER().
public bool IsWindowFunction { get; set; }
Property Value
Precedence
Determines the priority of the expression in evaluation. Refer to Precedence.
public int Precedence { get; set; }
Property Value
PreferServerSide
If true
a greater effort will be made to execute
the expression on the DB server instead of in .NET.
public bool PreferServerSide { get; set; }
Property Value
ServerSideOnly
If true
The expression will only be evaluated on the
database server. If it cannot, an exception will
be thrown.
public bool ServerSideOnly { get; set; }
Property Value
Methods
CalcCanBeNull(IsNullableType, IEnumerable<bool>)
public static bool? CalcCanBeNull(Sql.IsNullableType isNullable, IEnumerable<bool> nullInfo)
Parameters
isNullable
Sql.IsNullableTypenullInfo
IEnumerable<bool>
Returns
- bool?
GetCanBeNull(ISqlExpression[])
protected bool GetCanBeNull(ISqlExpression[] parameters)
Parameters
parameters
ISqlExpression[]
Returns
GetExpression<TContext>(TContext, IDataContext, SelectQuery, Expression, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression>)
public virtual ISqlExpression? GetExpression<TContext>(TContext context, IDataContext dataContext, SelectQuery query, Expression expression, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression> converter)
Parameters
context
TContextdataContext
IDataContextquery
SelectQueryexpression
Expressionconverter
Func<TContext, Expression, ColumnDescriptor, ISqlExpression>
Returns
Type Parameters
TContext
GetIsPredicate(Expression)
public virtual bool GetIsPredicate(Expression expression)
Parameters
expression
Expression
Returns
GetObjectID()
Returns mapping attribute id, based on all attribute options.
public override string GetObjectID()
Returns
PrepareArguments<TContext>(TContext, string, int[]?, bool, List<Expression?>, List<SqlDataType>?, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression?>)
public static ISqlExpression[] PrepareArguments<TContext>(TContext context, string expressionStr, int[]? argIndices, bool addDefault, List<Expression?> knownExpressions, List<SqlDataType>? genericTypes, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression?> converter)
Parameters
context
TContextexpressionStr
stringargIndices
int[]addDefault
boolknownExpressions
List<Expression>genericTypes
List<SqlDataType>converter
Func<TContext, Expression, ColumnDescriptor, ISqlExpression>
Returns
Type Parameters
TContext
PrepareParameterValues<TContext>(TContext, MappingSchema, Expression, ref string?, bool, out List<Expression?>, bool, out List<SqlDataType>?, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression>)
public static void PrepareParameterValues<TContext>(TContext context, MappingSchema mappingSchema, Expression expression, ref string? expressionStr, bool includeInstance, out List<Expression?> knownExpressions, bool ignoreGenericParameters, out List<SqlDataType>? genericTypes, Func<TContext, Expression, ColumnDescriptor?, ISqlExpression> converter)
Parameters
context
TContextmappingSchema
MappingSchemaexpression
ExpressionexpressionStr
stringincludeInstance
boolknownExpressions
List<Expression>ignoreGenericParameters
boolgenericTypes
List<SqlDataType>converter
Func<TContext, Expression, ColumnDescriptor, ISqlExpression>
Type Parameters
TContext
ResolveExpressionValues<TContext>(TContext, string, Func<TContext, string, string?, string?>)
public static string ResolveExpressionValues<TContext>(TContext context, string expression, Func<TContext, string, string?, string?> valueProvider)
Parameters
Returns
Type Parameters
TContext