Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
DataMapper 1.6.2
-
None
-
None
Description
I have the following problem with EnumTypeHandler:
I have an Enum like this:
public Enum MyEnum:short
and an object with property, which is defined as an Nullable<MyEnum>
public MyEnum? PropertyMyEnum
– nullable enum. Result map has defined type : MyEnum
When I try to load list of objects, I get the following exception, when an object is not DBNull in DB:
Exception: ArgumentException Type provided must be an Enum.
in EnumTypeHandler class in method GetValueByIndex on line 97:
Enum.Parse(mapping.MemberType, dataReader.GetValue(mapping.ColumnIndex).ToString())
I think, that NullableEnumTypeHandler should be defined with code like this:
public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
{
if (dataReader.IsDBNull(mapping.ColumnIndex) == true)
else
{
if (mapping.MemberType.IsGenericType && mapping.MemberType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))
return Enum.Parse(mapping.MemberType, dataReader.GetValue(mapping.ColumnIndex).ToString());
}
}