I have made an extension method to EF entities:
public static IEnumerable<T> WildcardSearch<T>(this IEnumerable<T> entity,
string param, Func<T,
string> selector)
{
return entity.Where(l => SqlFunctions.PatIndex(param, selector(l)) > 0);
}
//exception: This function can only be invoked from LINQ to Entities.
result = context.FOO.WildcardSearch(id, x => x.Id).ToList();
I get the exception above if I try to use it.
However, if I run (what I assume) the very same code directly on my collection, it works as intented.
Why do I get the exception, and is there any way to fix this?
Similar threads suggest changing the type to IQueryable
, but it doesn't seem to help.
//this works
result = context.FOO.Where(x =>
SqlFunctions.PatIndex(id, x.Id) > 0).ToList();