EF7如何通过ThenInclude方法传递属性

时间:2016-03-14 18:41:48

标签: c# entity-framework entity-framework-core coreclr

我在ASP.NET5应用程序中实现了Repository和UnitOfWork Pattern。 我想传递我想要包含在查询中的内容。

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

包含方法

 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;
    }

通过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);

从Entity Framework 7开始,有ThenInclude()方法,它包含included属性的属性。

它接受表达式作为参数

Expression<Func<object, TProperty>> navigationPropertyPath

编辑:任何人都知道或有同样的问题吗?

0 个答案:

没有答案