Мне нужно сделать рекурсивный вызов с включением в базу данных (EF 6.2.0), возможно ли сделать это универсальным способом?
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);
С помощью этого кода я получаю все коллекцииродительского элемента, но я не могу получить данные коллекций своих детей.