Table of Contents

Class ExpressionMethodAttribute

Namespace
LinqToDB
Assembly
linq2db.dll

When applied to method or property, tells linq2db to replace them in queryable LINQ expression with another expression, returned by method, specified in this attribute.

Requirements to expression method:

- expression method should be in the same class and replaced property of method; - method could be private.

When applied to property, expression: - method should return function expression with the same return type as property type; - expression method could take up to two parameters in any order - current object parameter and database connection context object.

When applied to method: - expression method should return function expression with the same return type as method return type; - method cannot have void return type; - parameters in expression method should go in the same order as in substituted method; - expression could take method instance object as first parameter; - expression could take database connection context object as last parameter; - last method parameters could be ommited from expression method, but only if you don't add database connection context parameter.

[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
public class ExpressionMethodAttribute : MappingAttribute, _Attribute
Inheritance
ExpressionMethodAttribute
Implements
Inherited Members
Extension Methods

Constructors

ExpressionMethodAttribute(LambdaExpression)

Creates instance of attribute.

public ExpressionMethodAttribute(LambdaExpression expression)

Parameters

expression LambdaExpression

Substitution expression.

ExpressionMethodAttribute(string)

Creates instance of attribute.

public ExpressionMethodAttribute(string methodName)

Parameters

methodName string

Name of method in the same class that returns substitution expression.

ExpressionMethodAttribute(string?, string)

Creates instance of attribute.

public ExpressionMethodAttribute(string? configuration, string methodName)

Parameters

configuration string

Connection configuration, for which this attribute should be taken into account.

methodName string

Name of method in the same class that returns substitution expression.

Properties

Alias

Gets or sets alias for substitution expression. Note that alias can be overriden by projection member name.

public string? Alias { get; set; }

Property Value

string

Expression

Substitution expression.

public LambdaExpression? Expression { get; set; }

Property Value

LambdaExpression

IsColumn

Gets or sets calculated column flag. When applied to property and set to true, Linq To DB will load data into property using expression during entity materialization.

public bool IsColumn { get; set; }

Property Value

bool

MethodName

Name of method in the same class that returns substitution expression.

public string? MethodName { get; set; }

Property Value

string

Methods

GetObjectID()

Returns mapping attribute id, based on all attribute options.

public override string GetObjectID()

Returns

string