I have a dynamic Linq query
public static IQueryable<T> WhereHelper<T>(this IQueryable<T> source, string property, string propertyValue) where T : class
{
//STEP 1: Verify the property is valid
var searchProperty = typeof(T).GetProperty(property);
//STEP 2: Create the OrderBy property selector
var parameter = Expression.Parameter(typeof(T), "o");
MemberExpression member = Expression.Property(parameter, property);
MethodInfo method = typeof(string).GetMethod("Contains", new[] { typeof(string) });
ConstantExpression constant = Expression.Constant(propertyValue);
MethodCallExpression queryExpr = Expression.Call(member, method, constant);
ParameterExpression pe = Expression.Parameter(typeof(string), property);
MethodCallExpression whereCallExpression = Expression.Call(
typeof(Queryable),
"Where",
new Type[] { source.ElementType },
source.Expression,
Expression.Lambda<Func<string, bool>>(queryExpr, new ParameterExpression[] { pe }));
return source.Provider.CreateQuery<T>(whereCallExpression);
}
This function generates an error which is the following:
No generic method 'Where' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
An idea on the error, thank you