The problem is that the model
parameter from the firstItem
expression is not the same as modelParameter
. In expression trees, parameters are not compared by name, but by reference.
This means that the simplest solution is to reuse the model
parameter from firstItem
, instead of creating your own parameter:
var modelParameter = firstItem.Parameters.Single();
With this modification, your code will work.