title: How can I make this query work in LINQ to Entities?
body: <p>I have to following code: </p>
  
  <pre class="lang-cs prettyprint-override"><code>private static bool DoesColValueExist&lt;T&gt;(IQueryable dataToSearchIn, string colName, string colValue)
  {
      int noOfClients = 1;
      Type type = typeof(T);
      if (colValue != "" &amp;&amp; colName != "")
      {
          var property = type.GetProperty(colName);
          var parameter = Expression.Parameter(type, "p");
          var propertyAccess = Expression.MakeMemberAccess(parameter, property);
          Expression left = Expression.Call(propertyAccess, typeof(object).GetMethod("ToString", System.Type.EmptyTypes));
          left = Expression.Call(left, typeof(string).GetMethod("ToLower", System.Type.EmptyTypes));
          Expression right = Expression.Constant(colValue.ToLower(), typeof(string));
          MethodInfo method = typeof(string).GetMethod("Equals", new[] { typeof(string) });
          Expression searchExpression = Expression.Call(left, method, right);
  
  
          MethodCallExpression whereCallExpression = Expression.Call(
              typeof(Queryable),
              "Where",
              new Type[] { type },
              dataToSearchIn.Expression,
              Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(searchExpression, new ParameterExpression[] { parameter }));
          var searchedData = dataToSearchIn.Provider.CreateQuery(whereCallExpression);
          noOfClients = searchedData.Cast&lt;T&gt;().Count();
  
          if (noOfClients == 0)
              return false;
          else
              return true;
      }
      return true;
  }
  </code></pre>
  
  <p>It works with LINQ to SQL but with LINQ to Entities, I get the error:</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.</p>
  </blockquote>