How to filter nested/child collections of entities when including them in EF?
Example:
Let’s have standard Customer-Orders association. How to load all customers and include only their last three orders in their Orders collection?
Is there something like AssociateWith function from L2S for EF?
No, unfortunately the Object Services API in Entity Framework doesn’t expose a way to selectively load associated entities based on a condition.
One way to solve this problem is to filter the associated entities when projecting the results in a query:
Related resources: