Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-294

Nullable<Enum> not suported

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • DataMapper 1.6.2
    • None
    • DataMapper
    • None

    Description

      I have the following problem with EnumTypeHandler:

      I have an Enum like this:
      public Enum MyEnum:short

      { A, B, C }

      and an object with property, which is defined as an Nullable<MyEnum>
      public MyEnum? PropertyMyEnum

      { get; set; }

      – 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)

      { return DBNull.Value; }

      else
      {
      if (mapping.MemberType.IsGenericType && mapping.MemberType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))

      { Type enumType = Nullable.GetUnderlyingType(mapping.MemberType); return Enum.Parse(enumType, dataReader.GetValue(mapping.ColumnIndex).ToString()); }

      return Enum.Parse(mapping.MemberType, dataReader.GetValue(mapping.ColumnIndex).ToString());
      }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            dmusak Dusan Musak
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: