0

Hello I have the next entities:

public class Area
{
     public ICollection<Indicator> Indicators { get; set; }
}
public class Indicator
{
     public Operator GreenCondition { get; set; }
}
public class Operator
{
     public string Name { get; set; }
}

And in the logic I have:

 public Area Get(int id)
        {
            List<Expression<Func<Area, object>>> includes = new List<Expression<Func<Area, object>>>();
            includes.Add(x => x.Indicators);
            includes.Add(x => x.Indicators.Select(i => i.GreenCondition));
            includes.Add(x => x.Managers);


            Area area = repAreas.Get(includes, a => a.Id == id && a.Active);

            return area;
        }

And in my logic of repository I have:

public T Get(IEnumerable<Expression<Func<T, object>>> includes, Func<T, bool> predicate)
        {
            var query = _objectSet.AsQueryable<T>();


           if(!(includes is null))
            {                
                query = includes.Aggregate(query, (current, include) => current.Include(include));
            }

            return query.Where(predicate).FirstOrDefault();
        }

But when is going to execute the return line it gives error that can't do the selected part.

Basically what I want is to show everyting from an Area using generic and reflection.

Monolith
  • 1,067
  • 1
  • 13
  • 29
Daniel Acevedo
  • 79
  • 1
  • 1
  • 11
  • Like this https://stackoverflow.com/questions/49593482/entity-framework-core-2-0-1-eager-loading-on-all-nested-related-entities/49597502#49597502? The way you asked it makes it duplicate of https://stackoverflow.com/questions/52997082/translating-generic-eager-load-method-from-ef6-to-ef-core/53053633#53053633 – Ivan Stoev Apr 26 '19 at 21:03
  • That could work yes but i was thinking in a less complecated solution if it exist, thank you very much – Daniel Acevedo Apr 26 '19 at 21:07

0 Answers0