EnumAsInt field not loading when nullable [4.0.54]

Using MySQL Ormlite.

An enum

[EnumAsInt]
public enum MyEnum
{
  Zero = 0,
  One = 1
}

used as a nullable field in a class

public class MyObj
{
  public int Id {get; set;}   
  public MyEnum? Test {get;set;}
}

won’t load the saved value

e.g.

// Insert or Update an object into database with ID=1 and Value = One (1)
var a = new MyObj();
a.Id = 1;
a.Test = MyEnum.One;
Db.Insert<MyObj>(a);
// row in database has Test==1

a = Db.Single<MyObj>(new { Id = 1});
// a.Test is Zero, should be One

If you change the definition class to remove the nullable Test field, it works as expected.

public class MyObj
{
  public int Id {get; set;}   
  public MyEnum Test {get;set;}
}

then

// Insert or Update an object into database with ID=1 and Value = One (1)
var a = new MyObj();
a.Id = 1;
a.Test = MyEnum.One;
Db.Insert<MyObj>(a);
// row in database has Test==1

a = Db.Single<MyObj>(new { Id = 1});
// a.Test is One

This should now be resolved in this PR.

This fix is available from v4.0.55 that’s now available on MyGet.