Cannot convert expression type 'lambda expression' to return type 'System.Linq.Expressions.Expression<System.Func<IProduct,string,bool>>'

c#, lambda

Solution

Your first function is going to need two arguments. `Func<x,y,z>` defines two parameters and the return value. Since you have both an `IProduct` and a `string` as parameters, you'll need two arguments in your lambda.

  public static Expression<Func<IProduct, string, bool>> IsValidExpression(string val)
  {
        return ((h, i) => h.product_name == val);
  }

Your second function is only `Func<x,y>`, so that means that the function signature has but one parameter, and thus your lambda statement compiles.

Problem

Ok, I'm lost. Why is the 1st function WRONG (squiglies in the lambda expression), but the 2nd one is RIGHT (meaning it compiles)? ``` public static Expression<Func<IProduct, string, bool>> IsValidExpression(string val) { return (h => h.product_name == val); } public static Expression<Func<IProduct, bool>> IsValidExpression2() { return (m => m.product_name == "ACE"); } ```

Original source