.AsExpandable in Linq to Entity

entity-framework lambda linq

Question

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?

1
17
6/5/2015 1:32:17 PM

Accepted Answer

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

12
12/3/2019 8:09:30 PM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow