Lambda to Expression tree conversion

Viewed 25509

I will keep it really simple,

How do I get expression tree out of lambda??

or from query expression ?

3 Answers

Just to expand on Konrad's answer, and to correct Pierre, you can still generate an Expression from an IL-compiled lambda, though it's not terribly elegant. Augmenting Konrad's example:

// Gives you a lambda:
Func<int, int> f = x => x * 2;

// Gives you an expression tree:
Expression<Func<int, int>> g = x => f(x);
Related