Ok, it turns out the '1' returned is a 'decimal', not an 'int'. So when I compile the lambda and invoke it as:
((ProjectionValueProducerFunc)((ValueListProjectionDefinition)toExecute.Projection).ProjectionInstantiatorLambda.Compile())(new object[] { 1}, new int[] {0})
results in true.
same as:
((ProjectionValueProducerFunc)((ValueListProjectionDefinition)toExecute.Projection).ProjectionInstantiatorLambda.Compile())(
new object[] {(decimal)1}, new int[] {0})
But, the compiled variant of the same lambda (compiled exactly as above), fails when I call it as:
_valueProducerFunc(new object[] {(decimal)1}, new int[] {0})
It fails with a cast exception.
it succeeds when I do:
_valueProducerFunc(new object[] {1}, new int[] {0})
Lambda really (object)(bool)Convert.ChangeType(values[indices[0]], typeof(bool))....
(edit)
, there are 2 steps of course in the projection system: from raw value array from reader to an object array which is then passed to the result projector. The first step fails, the lambda I was looking at is the second lambda. Looking into what the first lambda is ...
(edit) found it. the raw value -> value for projection array lambda is:
(System.Object)((System.Int32)$values[$indices[0]] > 0)
and this of course fails if the value is a decimal. Problem is: this code is ran a lot of times during a fetch. Adding a Convert.ChangeType() method call will likely cost in performance, so I've to check where this int32 cast comes from.