0

I forgot how work with expressions. But I need multilines

    Expression<Func<Location, string>> f = location =>
    {
        string phone = location.Phone;
        PhoneNumberHelper.TryFormat(location.Phone, out phone);
        return phone;
    };

Error 2 A lambda expression with a statement body cannot be converted to an expression tree

Mediator
  • 14,951
  • 35
  • 113
  • 191
  • If this is about entity framework or like, please mention in question. It matters. – Sriram Sakthivel Nov 26 '14 at 09:11
  • That duplicate is really "Why can't I use multiline lambdas with entity framework". It just says that you can't convert them to expressions. It doesn't cover why you can't convert them to expressions outside of the LINQ context. Of course I suspect the answer is the trivial "Expressions can't do that" but I'm sure more insight into this can be given. – Chris Nov 26 '14 at 09:14
  • @Mediator - see the deleted answer by Sriram for a good way to work around the problem. – Sean Nov 26 '14 at 10:24

1 Answers1

0

I believe that you can't do that in this way.

For more information how to make multi-statement expression look at Expression Trees (C# and Visual Basic) section Creating Expression Trees by Using the API.