Dear all,
I need use Lambda Expression in my method
public static class QueryableDynamicExtension
{
public static IQueryable<T> DynamicEquals<T>(
this IQueryable<T> query,
string field,
object value)
{
Expression<Func<T, bool>> expr = ???
return query.Where(expr);
}
}
In this method, I want it return same as
IQueryable<Article> articles = new ModelDataContext().Articles.Where(m => m.CategoryId == 5);
// I want replace by
IQueryable<Article> articles = new ModelDataContext().Articles.DynamicEquals("CategoryId", 5);
How should I build the "expr" in this case? Please help.