Enum char supported

Just a quick question, I have an existing db I’m reading from that use’s char(1) column. I mapped this as an Enum using the char values but I can’t get ormlite to populate the enum.

Are enum char values supported or do I need a custom converter?

public enum SomeEnum
    {
        Value1 = 'A', 
        Value2 = 'B', 
        Value3 = 'C', 
        Value4 = 'D'
    }

Honestly I’ve never even seen that before, but looks like they’re treated as ints with the char value in Ascii:

public enum SomeEnum : int
{
    Value1 = 'A', 
    Value2 = 'B', 
    Value3 = 'C', 
    Value4 = 'D'
}

$$"Value1: {(int)SomeEnum.Value1}".Print(); //65
$$"Value4: {(int)SomeEnum.Value4}".Print(); //68

OrmLite by default is just treating it a string (i.e. tries to save Value1), so its most likely going to need to be added in OrmLite with a custom [EnumAsChar] attribute, i.e. similar to how [EnumAsInt] is implemented.

1 Like

I’ve added support for char enums in this commit where you can annotate char enums with the new [EnumAsChar] attribute, e.g:

[EnumAsChar]
public enum SomeEnum
{
    Value1 = 'A', 
    Value2 = 'B', 
    Value3 = 'C', 
    Value4 = 'D'
}

Where it will store the char value in a CHAR(1) column.

This change is available from v5.5.1 that’s now available on MyGet.

1 Like

Fab, thanks @mythz :thumbsup: