I need to make a recursive call with includes to a database (EF 6.2.0), is it possible to do it in a generic way?
public class Option
{
public long OptionID { get; set; }
public long Property1 { get; set; }
public long Property2 { get; set; }
public long Property3 { get; set; }
public long Property4 { get; set; }
}
public class ClassOne
{
public long OrderID { get; set; }
public long OptionID { get; set; }
public long Property1 { get; set; }
public long Property2 { get; set; }
public long Property3 { get; set; }
public long Property4 { get; set; }
public virtual Option Option { get; set; }
public virtual ICollection<ClassOne> CollectionOne { get; set; } = new HashSet<ClassOne>();
public virtual ICollection<ClassTwo> CollectionTwo { get; set; } = new HashSet<ClassTwo>();
}
public ICollection<TEntity> Find(Expression<Func<TEntity, bool>> currentExpression, IncludeProperties includeProperties)
{
using (var currentContext = new TContext())
{
return (includeProperties == IncludeProperties.None
? new List<Expression<Func<TEntity, object>>>()
: PropertyInfoToExpression(GetVirtualProperties(new TEntity())))
.Aggregate(currentContext.Set<TEntity>().AsQueryable(),
(x, includeProperty) => x.Include(includeProperty)).Where(currentExpression).ToList();
}
}
_classOneRepository.Find(x => x.Property1 == 1), IncludeProperties.All);
With this code I get all the collections of the parent item, but I can not get the data of collections of their children.