title: "Incorrect number of parameters supplied for lambda declaration" creating Lambda Expression
body: <p>We have create this LinqExtension class to provide a Like method to Linq. Contains is not useful for us because we would like to do searchs like "%a%b%", in StackOverFlow we have found several post that are using method PatIndex from SqlFunction class to do It with Entity Framework.</p>
  
  <p>To keep clean code and easy reusable we are trying to do an extension method to encapsulate PatIndex call</p>
  
  <pre><code>public static IQueryable&lt;TSource&gt; WhereLike&lt;TSource&gt;(
    this IQueryable&lt;TSource&gt; source,
    Expression&lt;Func&lt;TSource, string&gt;&gt; valueSelector,
    string value
  )
  {
    return source.Where(BuildLikeExpression(valueSelector, value));
  }
  
  public static Expression&lt;Func&lt;TElement, bool&gt;&gt; BuildLikeExpression&lt;TElement&gt;(
    Expression&lt;Func&lt;TElement, string&gt;&gt; valueSelector,
    string value
  )
  {
    if (valueSelector == null)
      throw new ArgumentNullException("valueSelector");
  
    var method = GetLikeMethod(value);
  
    var body = Expression.Call(method, valueSelector.Body, Expression.Constant(value));
  
    var parameter = valueSelector.Parameters.Single();
    var expressionConvert = Expression.Convert(Expression.Constant(0), typeof(int?));
    return Expression.Lambda&lt;Func&lt;TElement, bool&gt;&gt; (Expression.GreaterThan(body, expressionConvert));
  }
  
  private static MethodInfo GetLikeMethod(string value)
  {
    var methodName = "PatIndex";
    Type stringType = typeof(SqlFunctions);
    return stringType.GetMethod(methodName);
  }
  </code></pre>
  
  <p>The problem is when we call this new method we get the error <strong>Incorrect number of parameters supplied for lambda declaration</strong> at </p>
  
  <pre><code>return Expression.Lambda&lt;Func&lt;TElement, bool&gt;&gt; (Expression.GreaterThan(body, expressionConvert));
  </code></pre>
  
  <p>What are we missing to do it properly?</p>