score:2

Accepted answer

i think you want to use expression.andalso (a short-circuiting and) on the two predicate expressions in question to construct the body of the expression-tree.

var body = expression.andalso(keyexists, valuecorresponds);
return expression.lambda<func<address, bool>>(body, datafields);

edit: (if you want to stick with your existing technique)

my guess is that your and method is an extension-method from the linqkit library. if so, note that this extension involves 'invoking' the right-hand side expression with the parameters of the first expression as part of producing the result. if this isn't acceptable to you (linq provider limitations, perhaps?), you can use the useful expand extension that also comes with this library to 'inline' the invoked expression.

return expression.lambda<func<address, bool>>(keyexists, datafields)
                 .and(expression.lambda<func<address, bool>>(valuecorresponds, datafields))
                 .expand();

but this is massive overkill in this case; my advice is to go with my first sample.


Related Query

More Query from same tag