3

这不起作用,但应该让您了解我想要实现的目标:

public static IEnumerable<T> MyMethod<T>(this IEnumerable<T> entity, 
                               string param, string SomeProp)
{
    return entity.Where(l =>
    System.Data.Objects.SqlClient.SqlFunctions.PatIndex(param, l.SomeProp) > 0);
}

我是否必须将整个Where()参数作为函数传递给MyMethod

4

1 回答 1

3

看到你的更新,你可以避免这样的重复:

public static IEnumerable<T> MyMethod<T>(this IEnumerable<T> entity, 
                               string param, Func<T, string> selector)
{
    return entity.Where(l =>
    System.Data.Objects.SqlClient.SqlFunctions.PatIndex(param, selector(l)) > 0);
}
于 2013-06-14T14:29:59.307 回答