ValueConverter Class

Definition

Defines conversions from an object of one type in a model to an object of the same or different type in the store.

public abstract class ValueConverter
type ValueConverter = class
Public MustInherit Class ValueConverter
Inheritance
ValueConverter
Derived

Remarks

See EF Core value converters for more information.

Constructors

ValueConverter(LambdaExpression, LambdaExpression, Boolean, ConverterMappingHints)

Initializes a new instance of the ValueConverter class, allowing conversion of nulls.

Warning: this is currently an internal API since converting nulls to and from the database can lead to broken queries and other issues. See https://github.com/dotnet/efcore/issues/26230 for more information.

ValueConverter(LambdaExpression, LambdaExpression, ConverterMappingHints)

Initializes a new instance of the ValueConverter class.

Properties

ConvertFromProvider

Gets the function to convert objects when reading data from the store, setup to handle nulls, boxing, and non-exact matches of simple types.

ConvertFromProviderExpression

Gets the expression to convert objects when reading data from the store, exactly as supplied and may not handle nulls, boxing, and non-exact matches of simple types.

ConvertsNulls

If true, then the nulls will be passed to the converter for conversion. Otherwise null values always remain null.

By default, value converters do not handle nulls so that a value converter for a non-nullable property (such as a primary key) can be used for correlated nullable properties, such as any corresponding foreign key properties.

ConvertToProvider

Gets the function to convert objects when writing data to the store, setup to handle nulls, boxing, and non-exact matches of simple types.

ConvertToProviderExpression

Gets the expression to convert objects when writing data to the store, exactly as supplied and may not handle nulls, boxing, and non-exact matches of simple types.

MappingHints

Hints that can be used by the ITypeMappingSource to create data types with appropriate facets for the converted data.

ModelClrType

The CLR type used in the EF model.

ProviderClrType

The CLR type used when reading and writing from the store.

Methods

CheckTypeSupported(Type, Type, Type[])

Checks that the type used with a value converter is supported by that converter and throws if not.

ComposeWith(ValueConverter)

Composes another ValueConverter instance with this one such that the result of the first conversion is used as the input to the second conversion.

Applies to