Class ExpressionExtensions
- Namespace
- Microsoft.EntityFrameworkCore.Infrastructure
- Assembly
- Microsoft.EntityFrameworkCore.dll
Extension methods for Expression types.
This type is typically used by database providers (and other extensions). It is generally not used in application code.
public static class ExpressionExtensions
- Inheritance
-
ExpressionExtensions
- Inherited Members
Remarks
See Implementation of database providers and extensions for more information and examples.
Fields
ValueBufferTryReadValueMethod
MethodInfo which is used to generate an Expression tree representing reading a value from a ValueBuffer
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public static readonly MethodInfo ValueBufferTryReadValueMethod
Field Value
Methods
Assign(MemberExpression, Expression)
Creates a BinaryExpression that represents an assignment operation.
public static Expression Assign(this MemberExpression memberExpression, Expression valueExpression)
Parameters
memberExpression
MemberExpressionThe member to which assignment will be made.
valueExpression
ExpressionThe value that will be assigned.
Returns
- Expression
The BinaryExpression representing the assignment binding.
CreateEFPropertyExpression(Expression, IPropertyBase, bool)
Creates an Expression tree representing EF property access on given expression.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public static Expression CreateEFPropertyExpression(this Expression target, IPropertyBase property, bool makeNullable = true)
Parameters
target
ExpressionThe expression that will be root for generated read operation.
property
IPropertyBaseThe property to access.
makeNullable
boolA value indicating if the value can be nullable.
Returns
- Expression
An expression to access EF property on given expression.
CreateEqualsExpression(Expression, Expression, bool)
Creates an Expression tree representing equality comparison between 2 expressions using Equals(object, object) method.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public static Expression CreateEqualsExpression(Expression left, Expression right, bool negated = false)
Parameters
left
ExpressionThe left expression in equality comparison.
right
ExpressionThe right expression in equality comparison.
negated
boolIf the comparison is non-equality.
Returns
- Expression
An expression to compare left and right expressions.
CreateKeyValuesExpression(Expression, IReadOnlyList<IProperty>, bool)
Creates an Expression tree representing reading of a key values on given expression.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public static Expression CreateKeyValuesExpression(this Expression target, IReadOnlyList<IProperty> properties, bool makeNullable = false)
Parameters
target
ExpressionThe expression that will be root for generated read operation.
properties
IReadOnlyList<IProperty>The list of properties to use to generate key values.
makeNullable
boolA value indicating if the key values should be read nullable.
Returns
- Expression
An expression to read the key values.
CreateValueBufferReadValueExpression(Expression, Type, int, IPropertyBase?)
Creates an Expression tree representing reading a value from a ValueBuffer
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public static Expression CreateValueBufferReadValueExpression(this Expression valueBuffer, Type type, int index, IPropertyBase? property)
Parameters
valueBuffer
ExpressionThe expression that exposes the ValueBuffer.
type
TypeThe type to read.
index
intThe index in the buffer to read from.
property
IPropertyBaseThe IPropertyBase being read if any.
Returns
- Expression
An expression to read the value.
GetMemberAccess(LambdaExpression)
Gets the MemberInfo represented by a simple member-access expression.
public static MemberInfo GetMemberAccess(this LambdaExpression memberAccessExpression)
Parameters
memberAccessExpression
LambdaExpressionThe expression.
Returns
- MemberInfo
The MemberInfo.
Remarks
This method is typically used to parse member access lambdas from fluent APIs.
GetMemberAccessList(LambdaExpression)
Returns a list of MemberInfo extracted from the given simple LambdaExpression.
public static IReadOnlyList<MemberInfo> GetMemberAccessList(this LambdaExpression memberAccessExpression)
Parameters
memberAccessExpression
LambdaExpressionThe expression.
Returns
- IReadOnlyList<MemberInfo>
The list of referenced members.
Remarks
Only simple expressions are supported, such as those used to reference a member.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
GetPropertyAccess(LambdaExpression)
Gets the PropertyInfo represented by a simple property-access expression.
public static PropertyInfo GetPropertyAccess(this LambdaExpression propertyAccessExpression)
Parameters
propertyAccessExpression
LambdaExpressionThe expression.
Returns
- PropertyInfo
The PropertyInfo.
Remarks
This method is typically used to parse property access lambdas from fluent APIs.
GetPropertyAccessList(LambdaExpression)
Returns a list of PropertyInfo extracted from the given simple LambdaExpression.
public static IReadOnlyList<PropertyInfo> GetPropertyAccessList(this LambdaExpression propertyAccessExpression)
Parameters
propertyAccessExpression
LambdaExpressionThe expression.
Returns
- IReadOnlyList<PropertyInfo>
The list of referenced properties.
Remarks
Only simple expressions are supported, such as those used to reference a property.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
MakeMemberAccess(Expression?, MemberInfo)
Creates a MemberExpression that represents accessing either a field or a property.
public static MemberExpression MakeMemberAccess(this Expression? expression, MemberInfo member)
Parameters
expression
ExpressionAn Expression that represents the object that the member belongs to.
member
MemberInfoThe MemberInfo that describes the field or property to be accessed.
Returns
- MemberExpression
The MemberExpression that results from calling the appropriate factory method.
Print(Expression, int?)
Creates a printable string representation of the given expression.
public static string Print(this Expression expression, int? characterLimit = null)
Parameters
expression
ExpressionThe expression.
characterLimit
int?An optional limit to the number of characters included. Additional output will be truncated.
Returns
- string
The printable representation.
TryGetEFPropertyArguments(MethodCallExpression, out Expression?, out string?)
If the given a method-call expression represents a call to Property<TProperty>(object, string), then this method extracts the entity expression and property name.
public static bool TryGetEFPropertyArguments(this MethodCallExpression methodCallExpression, out Expression? entityExpression, out string? propertyName)
Parameters
methodCallExpression
MethodCallExpressionThe method-call expression for Property<TProperty>(object, string)
entityExpression
ExpressionThe extracted entity access expression.
propertyName
stringThe accessed property name.
Returns
- bool
true if the method-call was for Property<TProperty>(object, string); false otherwise.
TryGetIndexerArguments(MethodCallExpression, IModel, out Expression?, out string?)
If the given a method-call expression represents a call to indexer on the entity, then this method extracts the entity expression and property name.
public static bool TryGetIndexerArguments(this MethodCallExpression methodCallExpression, IModel model, out Expression? entityExpression, out string? propertyName)
Parameters
methodCallExpression
MethodCallExpressionThe method-call expression for indexer.
model
IModelThe model to use.
entityExpression
ExpressionThe extracted entity access expression.
propertyName
stringThe accessed property name.