I tried to define a generic loading method. I call this generic loading method with an array of expressions like this:
var includes = new Expression<Func<CatalogItem, object>>[]
{
ci => ci.Catalog.Select(ci => ci.Supplier.Region),
ci => ci.Test
}
In the method I create an IQueryable:
IQueryable<TAggregateRoot> queryable = dbContext.Set<TAggregateRoot>();
Then for each Expression I want to load the respective data like this:
foreach (var include in includes)
{
queryable = queryable.Include(include);
}
But this only works when the Expression is only one level. With multiple levels it throws an error.
Since there is no ThenInclude I have to use the EntityFrameworkQueryableExtensions. I tried it like this
queryable = EntityFrameworkQueryableExtensions.ThenInclude(queryable, include);
But this does not work either.
I cannot find any documentation to this problem. How do I solve this problem and how do I use EntityFrameworkQueryableExtensions.ThenInclude?