.AsExpandable in Linq to Entity
Entity Framework's query processing pipeline cannot handle invocation expressions, which is why you need to call AsExpandable on the first object in the query. By calling AsExpandable, you activate LINQKit's expression visitor class which substitutes invocation expressions with simpler constructs that Entity Framework can understand.
— Josef Albahari
For more details I would recommend read from the author of LinqPad
- There is no implicit conversion from a method group to an
Expression<TDelegate>
(of a corresponding delegate typeTDelegate
). - But there is an implicit conversion from a method group to a delegate of a matching signature. Therefore only the
IEnumerable
overload matches.
Of course, that's not to say that you need to use a lambda. Just write this:
ctx.Set<Person>().AsExpandable().Where(ByName);
Since you're passing in an expression (ByName
is, after all, an Expression<Person, bool>
already, which is exactly what Queryable.Where<Person>
requires) this will evaluate as a query, not in linq to objects.