Class MapValueAttribute
Defines bidirectional mapping between enum field value, used on client and database value, stored in database and used in queries. Enumeration field could have multiple MapValueAttribute attributes.
Mapping from database value to enumeration performed when you load data from database. Linq2db will search for enumeration field with MapValueAttribute with required value. If attribute with such value is not found, you will receive LinqToDBException error. If you cannot specify all possible values using MapValueAttribute, you can specify custom mapping using methods like SetConvertExpression<TFrom, TTo>(Expression<Func<TFrom, TTo>>, bool, ConversionType).
Mapping from enumeration value performed when you save it to database or use in query. If your enum field has multiple MapValueAttribute attributes, you should mark one of them as default using IsDefault property.
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class MapValueAttribute : MappingAttribute, _Attribute
- Inheritance
-
MapValueAttribute
- Implements
- Inherited Members
- Extension Methods
Constructors
MapValueAttribute()
Adds MapValueAttribute mapping to enum field. If you don't specify Value property,
null
value will be used.
public MapValueAttribute()
MapValueAttribute(object?)
Adds MapValueAttribute to enum field.
public MapValueAttribute(object? value)
Parameters
value
objectDatabase value, mapped to current enumeration field.
MapValueAttribute(object, bool)
Adds MapValueAttribute to enum field.
public MapValueAttribute(object value, bool isDefault)
Parameters
value
objectDatabase value, mapped to current enumeration field.
isDefault
boolIf
true
, database value from this attribute will be used for mapping to database value.
MapValueAttribute(string, object)
Adds MapValueAttribute to enum field.
public MapValueAttribute(string configuration, object value)
Parameters
configuration
stringName of configuration, for which this attribute instance will be used.
value
objectDatabase value, mapped to current enumeration field.
MapValueAttribute(string, object?, bool)
Adds MapValueAttribute to enum field.
public MapValueAttribute(string configuration, object? value, bool isDefault)
Parameters
configuration
stringName of configuration, for which this attribute instance will be used.
value
objectDatabase value, mapped to current enumeration field.
isDefault
boolIf
true
, database value from this attribute will be used for mapping to database value.
Properties
IsDefault
If true
, Value property value will be used for conversion from enumeration to
database value.
public bool IsDefault { get; set; }
Property Value
Value
Database value, to which current enumeration field will be mapped when used in query or saved to database. This value, when loaded from database, will be converted to current enumeration field.
public object? Value { get; set; }
Property Value
Methods
GetObjectID()
Returns mapping attribute id, based on all attribute options.
public override string GetObjectID()