EF7 how to pass property to be Included By ThenInclude Method

Viewed 592

I have implemented Repository and UnitOfWork Pattern in my ASP.NET5 app. I would like to pass things i want to include in the query.

 public virtual IEnumerable<TEntity> Get(params Expression<Func<TEntity, object>>[] includes)
    {
        var query = Context.Set<TEntity>().AsQueryable();
        return Include(query, includes);
    }

Include Method

 private IQueryable<TEntity> Include(IQueryable<TEntity> query, params Expression<Func<TEntity, object>>[] includes)
    {
        if (includes != null)
        {
            foreach (var i in includes)
            {
               query = query.Include(i);
            }
        }
        return query;
    }

Call trough UnitOfWork

//PREDICATE BUILDER CREATE METHOD JUST CREATES EXPRESSION
var comments = PredicateBuilder.Create<DAL.Report, object>(x => x.Comments);

//THIS DOESNT WORK ANYMORE
var commentsCreator = PredicateBuilder.Create<DAL.Report, object>(x => x.Comments.Select(y => y.Creator)); 


var dalReports = unitOfWork.Reports.Get(comments, commentsCreator);

As of Entity Framework 7 there is ThenInclude() Method which includes properties of the included property.

And it accepts expression as parameter

Expression<Func<object, TProperty>> navigationPropertyPath

Edit: Anyone knows anything or had the same problem ?

0 Answers
Related