public static IQueryable<T> Like<T>(this IQueryable<T> source, string propertyName, string keyword) { var type = typeof(T); var property = type.GetProperty(propertyName); var parameter = Expression.Parameter(type, "p"); var propertyAccess = Expression.MakeMemberAccess(parameter, property); var constant = Expression.Constant("%" + keyword + "%"); var like = typeof(SqlMethods).GetMethod("like", new Type[] { typeof(string), typeof(string) }); MethodCallExpression methodExp = Expression.Call(null, like, propertyAccess, constant); Expression<Func<T, bool>> lambda = Expression.Lambda<Func<T, bool>>(methodExp, parameter); return source.Where(lambda); }which is applied in the following context:
var clients = Db.Clients; // Should set type of clients to IQueryable<Clients> .... if (!string.IsNullOrEmpty(qtype) && !string.IsNullOrEmpty(query)) { clients = clients.Like(qtype, query); } int Total = clients.Count()The last line now generates this error: