On Mon, 23 Jan 2012 23:08:03 -0800 (PST), Ramkrishnan . wrote:
> hi,
>
> i got an error "A lambda expression with a statement body cannot be
> converted to an expression tree" when i write below code.
>
> data = is the iquerable object.
>
> how to solve tis error.
Don't try to convert a lambda expression declared with a statement body to
an expression tree.
You might try to move the code into a method which then is used as the sole
expression within the lambda. However, in many cases when you do that
you'll just run into a different problem: the lambda expression can use
only specific, supported elements, which your separate method undoubtedly
will not be included in.
I'm not familiar enough with all the ins and outs of expression trees to
know for sure you'll run into that problem, and your post doesn't really
contain enough context to know for sure anyway. It's worth a try. But
don't be surprised if it doesn't work either. :)
In the end, the real solution may be simply to implement the query logic in
a different way (i.e. using plain objects rather than LINQ to SQL, for
example).
Pete