Created
January 4, 2013 10:59
-
-
Save yagopv/4451663 to your computer and use it in GitHub Desktop.
DDD. Include multiple Related Entities using eager loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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