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 will 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 am not familiar enough with all the ins and outs of expression trees to
know for sure you will run into that problem, and your post does not really
contain enough context to know for sure anyway. it is worth a try. But
do not be surprised if it does not 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