EF Core包括Grandchild GenericRepository

时间:2017-09-12 15:05:00

标签: entity-framework-core

我使用GenericRepository在EF Core上使用Eager Loading,在这种情况下我可以加载CategoriaNutrientes但是如果我尝试加载Nutriente

categoriaService.FindBy((i => i.CategoriaNutrientes.Select(x=>x.Nutriente)))

我有这个错误:

  

System.InvalidOperationException:'属性表达式' i => {从   [i] .ManyToManyChilds中的ManyToManyChild x选择[x] .GrandChild}'   无效。表达式应代表属性访问权限:' t =>   t.MyProperty&#39 ;.有关包含相关数据的更多信息,请参阅   http://go.microsoft.com/fwlink/?LinkID=746393'

public class Categoria:BaseEntidadeExecutora
{
    public Int64 Id { get; set; }
    public string NomeCategoria { get; set; }
    public Int64 QtdeMinimaRefeicao { get; set; }
    public string FormaCalculo { get; set; }
    public Int64 NecessidadeDiariaMinima { get; set; }
    public ICollection<CategoriaNutriente> CategoriaNutrientes { get; set; }
    public ICollection<UnidadeEnsinoCategoria> UnidadeEnsinoCategorias { get; set; }
}

public class CategoriaNutriente : BaseEntity
{
    public Int64 IdCategoria { get; set; }
    public Categoria Categoria {get;set;}
    public Int64 IdNutriente { get; set; }
    public Nutriente Nutriente { get; set; }
    public Int64 NecessidadeNutricional { get; set; }
}

categoriaService.FindBy((i => i.CategoriaNutrientes.Select(x=>x.Nutriente)))

public IEnumerable<T> FindBy(params Expression<Func<T, object>>[] includes)
{
    IQueryable<T> set = entities;

    var entity = (includes.Aggregate(set, (current, include) => current.Include(include)).ToList() ?? default(ICollection<T>));
}

0 个答案:

没有答案