Skip to content

Instantly share code, notes, and snippets.

@yagopv
Created January 4, 2013 10:59
Show Gist options
  • Save yagopv/4451663 to your computer and use it in GitHub Desktop.
Save yagopv/4451663 to your computer and use it in GitHub Desktop.
DDD. Include multiple Related Entities using eager loading
public static IQueryable<T> IncludeMultiple<T>(this IQueryable<T> query, params Expression<Func<T, object>>[] includes)
where T : class
{
if (includes != null)
{
query = includes.Aggregate(query,
(current, include) => current.Include(include));
}
return query;
}
var query = context.Customers
.IncludeMultiple(
c => c.Address,
c => c.Orders.Select(o => o.OrderItems));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment