Gilles,

Luke's Binder suggestion as posted on SourceForge did work, however as he
mentioned, there should be a better way without throwing out type safety.

I went through the code for getting selectKeys and noticed the similarity
with QueryForObject since they both go through
MappedStatement.ExecuteQueryForObject() and
MappedStatement.ApplyResultMap().

I ended up finding why both QueryForObject() and using a selectKey return a
System.Decimal when using Oracle even if the resultClass is specified as int
(or string or anything else).  The generated ResultProperty for a primitive
resultClass didn't have a TypeHandler specified, so the resulting object was
being handled by grabbing the db/provider type.

Thankfully, it's a quick fix!  :-)

Here's the area in MappedStatement.ApplyResultMap() (lines 383 to 392...the
"property.TypeHandler..." line is the fix):

// Check if the ResultClass is a 'primitive' Type
if (Type.GetTypeCode(outObject.GetType()) != TypeCode.Object)
{
        // Create a ResultProperty
        ResultProperty property = new ResultProperty();
        property.PropertyName = "value";
        property.ColumnIndex = 0;
        property.TypeHandler =
TypeHandlerFactory.GetTypeHandler(outObject.GetType());

        SetObjectProperty(request, request.ResultMap, property, ref
outObject, reader);
}

This should hopefully resolve any weird errors others may be getting when
specifying a primitive result class but not actually getting the object of
that type.  Haven't heard many complaints though!  hehe

Roberto

Reply via email to