Class ValueConverter
- Assembly
- Microsoft.EntityFrameworkCore.dll
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
- Inheritance
-
ValueConverter
- Derived
- Inherited Members
Remarks
See EF Core value converters for more information and examples.
Constructors
ValueConverter(LambdaExpression, LambdaExpression, ConverterMappingHints?)
Initializes a new instance of the ValueConverter class.
protected ValueConverter(LambdaExpression convertToProviderExpression, LambdaExpression convertFromProviderExpression, ConverterMappingHints? mappingHints = null)
Parameters
convertToProviderExpression
LambdaExpressionThe 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.
convertFromProviderExpression
LambdaExpressionThe 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.
mappingHints
ConverterMappingHintsHints that can be used by the ITypeMappingSource to create data types with appropriate facets for the converted data.
Remarks
See EF Core value converters for more information and examples.
ValueConverter(LambdaExpression, LambdaExpression, bool, 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 GitHub issue #26230 for more information and examples.
[EntityFrameworkInternal]
protected ValueConverter(LambdaExpression convertToProviderExpression, LambdaExpression convertFromProviderExpression, bool convertsNulls, ConverterMappingHints? mappingHints = null)
Parameters
convertToProviderExpression
LambdaExpressionThe 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.
convertFromProviderExpression
LambdaExpressionThe 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
boolIf true, then the nulls will be passed to the converter for conversion. Otherwise null values always remain null.
mappingHints
ConverterMappingHintsHints that can be used by the ITypeMappingSource to create data types with appropriate facets for the converted data.
Remarks
See EF Core value converters for more information and examples.
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.
public abstract Func<object?, object?> ConvertFromProvider { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
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.
public virtual LambdaExpression ConvertFromProviderExpression { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
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.
public abstract Func<object?, object?> ConvertToProvider { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
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.
public virtual LambdaExpression ConvertToProviderExpression { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
ConvertsNulls
If true, then the nulls will be passed to the converter for conversion. Otherwise null values always remain null.
public virtual bool ConvertsNulls { get; }
Property Value
Remarks
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.
See EF Core value converters for more information and examples.
MappingHints
Hints that can be used by the ITypeMappingSource to create data types with appropriate facets for the converted data.
public virtual ConverterMappingHints? MappingHints { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
ModelClrType
The CLR type used in the EF model.
public abstract Type ModelClrType { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
ProviderClrType
The CLR type used when reading and writing from the store.
public abstract Type ProviderClrType { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.
Methods
CheckTypeSupported(Type, Type, params Type[])
Checks that the type used with a value converter is supported by that converter and throws if not.
protected static Type CheckTypeSupported(Type type, Type converterType, params Type[] supportedTypes)
Parameters
type
TypeThe type to check.
converterType
TypeThe value converter type.
supportedTypes
Type[]The types that are supported.
Returns
- Type
The given type.
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.
public virtual ValueConverter ComposeWith(ValueConverter? secondConverter)
Parameters
secondConverter
ValueConverterThe second converter.
Returns
- ValueConverter
The composed converter.
Remarks
See EF Core value converters for more information and examples.