Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: DataMapper 1.6.2
    • Fix Version/s: None
    • Component/s: DataMapper
    • Labels:
      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());
      }
      }

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Dusan Musak
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development