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.
By calling AsExpandable, you activate LINQKit's expression visitor class which substitutes invocation expressions with simpler constructs that Entity Framework can understand. 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).
To execute a LINQ to Entities query against the Entity Framework, the LINQ query must be converted to a command tree representation that can be executed against the Entity Framework. LINQ to Entities queries are comprised of LINQ standard query operators (such as Select, Where, and GroupBy) and expressions (x > 10, Contact.LastName, and so on).
LINQ to Entities queries can be composed in two different syntaxes: query expression syntax and method-based query syntax. Query expression syntax and method-based query syntax are new in C# 3.0 and Visual Basic 9.0. For more information, see Queries in LINQ to Entities.
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
Expression<TDelegate>
(of a corresponding delegate type TDelegate
).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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With