我有这段代码:
public static Expression<Func<T, bool>> CreatePredicate<T>(string typeSearch, string searchField, string stringToSearch)
{
var parameter = Expression.Parameter(typeof(T));
var predicate = Expression.Lambda<Func<T, bool>>(
Expression.Call(
Expression.PropertyOrField(parameter, searchField),
"Contains", null,
Expression.Constant(stringToSearch.ToUpper())), parameter);
return predicate;
}
结果是:{Param_0 => Param_0.Username.Contains("MX")}
但我想这样:{Param_0 => Param_0.Username.ToUpper().Contains("MX")}
谢谢,
答案 0 :(得分:2)
public static Expression<Func<T, bool>> CreatePredicate<T>(string typeSearch, string searchField, string stringToSearch)
{
var parameter = Expression.Parameter(typeof(T));
var predicate = Expression.Lambda<Func<T, bool>>(
Expression.Call(
Expression.Call(Expression.PropertyOrField(parameter, searchField), "ToUpper", null),
"Contains", null,
Expression.Constant(stringToSearch.ToUpper())), parameter);
return predicate;
}