Declare your returnCode
variable as Expression<>>
and compiler will generate expression for you:
When a lambda expression is assigned to a variable, field, or parameter whose type is
Expression<TDelegate>
, the compiler emits instructions to build an expression tree.from Expression Class
But because your lambda returns anonymous type, instead of User
class instance, your Func<T, TRresult>
generic parameter does not match. Try with following:
Expression<Func<ICypherResultItem, User>> returnCode = (user) => user.As<User>;