I’m wondering if there is any support in OrmLite for using the [EnumMember] attribute on enum values when reading from or writing to the database.
For example:
public enum Status
{
[EnumMember(Value = "active")]
Active,
[EnumMember(Value = "inactive")]
Inactive
}
By default, OrmLite maps enums using either their string name or integer value. However, in my case, I need to use the values defined in the [EnumMember] attribute, since they match external data sources (e.g. "active" and "inactive").
I understand this is not supported out of the box, but is there a way to implement a custom Type Converters or similar to handle this mapping for specific enum types?
Or is there any recommended approach for handling this scenario?
I am using Firebird database.
No they’re ServiceContract attributes which only apply to DTO/Serialization but you should be able override the default EnumConverter and override it on your DialectProvider instance, e.g:
class MyEnumConverter : EnumConverter { ... }
//...
SqliteOrmLiteDialectProvider.Instance.EnumConverter = new MyEnumConverter();
PostgreSqlDialectProvider.Instance.EnumConverter = new MyEnumConverter();
// etc