1

私はこのコードを持っています:

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")}

ありがとう、

4

1 に答える 1

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;
}
于 2012-07-30T12:27:09.890 に答える