You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Michael Schall <mi...@gmail.com> on 2007/01/29 15:32:40 UTC
Exact type conversions
While upgrading from v1.3.1 I have found some breaking changes in current
SVN. Hopefully this will help someone else out there upgrading. I'm was
getting a "System.InvalidCastException: Specified cast is not valid." in the
DelegatePropertySetAccessor->ISet Members-> Set method.
I have a public enum:
Public Enum ObjectStatus
Inactive = -1
Deleted = 0
Active = 1
End Enum
Objects have a Status property of this type. This is stored as an smallint
in database. When attempting to set the Status property with the value 1, I
get the above error. The stack trace ends with:
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.InvalidCastException: Specified
cast is not valid.
at SetImplementation(Object , Object )
at
IBatisNet.Common.Utilities.Objects.Members.DelegatePropertySetAccessor.SetValue.Invoke(Object
instance, Object value)
at
IBatisNet.Common.Utilities.Objects.Members.DelegatePropertySetAccessor.Set(Object
target, Object value) in
C:\PROJECTS\Framework\src\IBatisNet.Common\Utilities\Objects\Members\DelegatePropertySetAccessor.cs:line
165
My SqlMap has the following result map:
<resultMap id="FooResultMap" class="Foo">
...
<result column="Status" property="Status" type="Int16"
dbType="smallint" />
...
</resultMap>
If I switch the above enum to
Public Enum ObjectStatus As Short 'Int16
Inactive = -1
Deleted = 0
Active = 1
End Enum
Or the resultMap to
<resultMap id="FooResultMap" class="Foo">
...
<result column="Status" property="Status" type="Int32"
dbType="smallint" />
...
</resultMap>
Or turn off ReflectionOptimizer in SqlMap.config file
useReflectionOptimizer="false"
The code works fine. By default(and suggestion of FxCop) Enum's have the
default datatype of Int32. It must have something to do with the
Reflection.Emit code.
Re: Exact type conversions
Posted by Gilles Bayon <ib...@gmail.com>.
The default underlying type of the enumeration elements is *int* and as your
enum don't have a type, iBATIS is right :-)
--
Cheers,
Gilles
<a href="http://www.amazon.com/gp/registry/6JCP7AORB0LE">Wish List</a>