Hello all,
i search for a dynamic linq-to-sql Contains (StartsWith / EndsWith) method.
I’ve tried the following code, but it didn't work.
Any ideas?
public static IQueryable<T> WhereContains<T, V>(this IQueryable<T> queryable, string propertyName, V propertyValue)
{
ParameterExpression pe = Expression.Parameter(typeof(T), "p");
Expression left = Expression.Property(pe, propertyName);
Expression right = Expression.Constant(propertyValue, typeof(V));
IQueryable<T> x = queryable.Where<T>(
Expression.Lambda<Func<T, bool>>(
Expression.Call(
typeof(T).GetMethod("Contains"),
left,
right),
new ParameterExpression[] { pe }));
return x;
}