Class ValueConverter<TModel, TProvider>
- 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 class ValueConverter<TModel, TProvider> : ValueConverter
Type Parameters
TModel
TProvider
- Inheritance
-
ValueConverter<TModel, TProvider>
- Derived
- Inherited Members
Remarks
See EF Core value converters for more information and examples.
Constructors
ValueConverter(Expression<Func<TModel, TProvider>>, Expression<Func<TProvider, TModel>>, ConverterMappingHints?)
Initializes a new instance of the ValueConverter<TModel, TProvider> class.
public ValueConverter(Expression<Func<TModel, TProvider>> convertToProviderExpression, Expression<Func<TProvider, TModel>> convertFromProviderExpression, ConverterMappingHints? mappingHints = null)
Parameters
convertToProviderExpression
Expression<Func<TModel, TProvider>>An expression to convert objects when writing data to the store.
convertFromProviderExpression
Expression<Func<TProvider, TModel>>An expression to convert objects when reading data from the store.
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(Expression<Func<TModel, TProvider>>, Expression<Func<TProvider, TModel>>, bool, ConverterMappingHints?)
Initializes a new instance of the ValueConverter<TModel, TProvider> 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]
public ValueConverter(Expression<Func<TModel, TProvider>> convertToProviderExpression, Expression<Func<TProvider, TModel>> convertFromProviderExpression, bool convertsNulls, ConverterMappingHints? mappingHints = null)
Parameters
convertToProviderExpression
Expression<Func<TModel, TProvider>>An expression to convert objects when writing data to the store.
convertFromProviderExpression
Expression<Func<TProvider, TModel>>An expression to convert objects when reading data from the store.
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 override 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 Expression<Func<TProvider, TModel>> ConvertFromProviderExpression { get; }
Property Value
- Expression<Func<TProvider, TModel>>
Remarks
See EF Core value converters for more information and examples.
ConvertFromProviderTyped
Gets the function to convert objects when reading data from the store.
public virtual Func<TProvider, TModel> ConvertFromProviderTyped { get; }
Property Value
- Func<TProvider, TModel>
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 override 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 Expression<Func<TModel, TProvider>> ConvertToProviderExpression { get; }
Property Value
- Expression<Func<TModel, TProvider>>
Remarks
See EF Core value converters for more information and examples.
ConvertToProviderTyped
Gets the function to convert objects when writing data to the store.
public virtual Func<TModel, TProvider> ConvertToProviderTyped { get; }
Property Value
- Func<TModel, TProvider>
Remarks
See EF Core value converters for more information and examples.
ModelClrType
The CLR type used in the EF model.
public override 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 override Type ProviderClrType { get; }
Property Value
Remarks
See EF Core value converters for more information and examples.