SqlFunctions.PatIndex扩展方法

时间:2019-07-01 15:15:33

标签: c# entity-framework-6

我写了一个通用函数,将PATINDEX查询添加到IQueryable。 但这没有任何作用。为什么?怎么了?请帮忙。

public static IQueryable<T> WhereIndex<T>(this IQueryable<T> ts,Expression<Func<T,string>> columnSelector, string pattern)  where T:class
{
    return ts.Where(t => SqlFunctions.PatIndex(pattern, columnSelector.Compile()(t)) > 0);
}       

方法调用:

dbc.Departments.WhereIndex(t => t.Name,"test%");        

0 个答案:

没有答案