I use ASP Net Core Web API and EF Core. There is an interesting magic that could not be comprehended.
IEfCotntext is IEfCotntext :
public interface IEfContext : IDisposable { DbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity; ... } public class EfContext : DbContext, IEfContext { ... public new DbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity { return base.Set<TEntity>(); } ... } Repository:
public class Repository<TEntity> : IRepository<TEntity> where TEntity : BaseEntity { public DbSet<TEntity> Entities { get { return dbset ?? context.Set<TEntity>(); } } ... public async Task<IQueryable<TEntity>> GetAsync(Expression<Func<TEntity, bool>> where = null, params Expression<Func<TEntity, object>>[] includes) { IQueryable<TEntity> query = Entities; if (includes != null) foreach (var include in includes) query = query.Include(include); if (where != null) query = query.Where(where); var result = await query.ToListAsync(); query = result.ToList().AsQueryable(); return query; } ... } Category Category:
public class Category : BaseEntity { public string Name { get; set; } public int? ParentId { get; set; } public virtual Category Parent { get; set; } public virtual ICollection<Product> Products { get; set; } public virtual ICollection<Category> Children { get; set; } } Through ICategoryService I try to get data from the database:
return await categoryRepository.GetAsync(model => model.ParentId == null, x => x.Children, x => x.Products); In the returned data for each object from Childred , the Childen and Products properties are null . But passing by the debugger
It is only when I try to get the Results View data is returned correctly.
Tried to close connections ( .ToList() ) wherever possible. But the function also continues to work incorrectly.

