Table of Contents

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

MethodInfo

Methods

Assign(MemberExpression, Expression)

Creates a BinaryExpression that represents an assignment operation.

public static Expression Assign(this MemberExpression memberExpression, Expression valueExpression)

Parameters

memberExpression MemberExpression

The member to which assignment will be made.

valueExpression Expression

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

The expression that will be root for generated read operation.

property IPropertyBase

The property to access.

makeNullable bool

A 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 Expression

The left expression in equality comparison.

right Expression

The right expression in equality comparison.

negated bool

If 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 Expression

The expression that will be root for generated read operation.

properties IReadOnlyList<IProperty>

The list of properties to use to generate key values.

makeNullable bool

A 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 Expression

The expression that exposes the ValueBuffer.

type Type

The type to read.

index int

The index in the buffer to read from.

property IPropertyBase

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

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

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

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

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

An Expression that represents the object that the member belongs to.

member MemberInfo

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

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

The method-call expression for Property<TProperty>(object, string)

entityExpression Expression

The extracted entity access expression.

propertyName string

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

The method-call expression for indexer.

model IModel

The model to use.

entityExpression Expression

The extracted entity access expression.

propertyName string

The accessed property name.

Returns

bool

true if the method-call was for indexer; false otherwise.