In Linq to Entity, what does
.AsExpandable() exactly do? Where and why to use it? Does it include all the related entities into query for lazy loading?
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 (of a corresponding delegate type). 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:
ctx.Set().AsExpandable().Where(ByName); Since you're passing in an expression (ByName is, after all, an Expression already, which is exactly what Queryable.Where requires) this will evaluate as a query, not in linq to objects.