Ok, I have tri-leveled entities with the following hierarchy: Course -> Module -> Chapter
Here was the original EF LINQ statement:
Course course = db
One may write an extension method like this:
///
/// Includes an array of navigation properties for the specified query
///
/// The type of the entity
/// The query to include navigation properties for that
/// The array of navigation properties to include
///
public static IQueryable Include(this IQueryable query, params string[] navProperties)
where T : class
{
foreach (var navProperty in navProperties)
query = query.Include(navProperty);
return query;
}
And use it like this even in a generic implementation:
string[] includedNavigationProperties = new string[] { "NavProp1.SubNavProp", "NavProp2" };
var query = context.Set()
.Include(includedNavigationProperties);