“A lambda expression with a statement body cannot be converted to an expression tree”

In using the EntityFramework, I get the error “A lambda expression with a statement body cannot be converted to an expression tree” when trying to compile the following code:

Obj[] myArray = objects.Select(o =>
{
    var someLocalVar = o.someVar;

    return new Obj() { 
    Var1 = someLocalVar,
    Var2 = o.var2 };
}).ToArray();

I don’t know what the error means and most of all how to fix it. Any help?

11 Answers
11

Leave a Comment