Search code examples
aspnetboilerplate

Repository Query Loading Related Data


The microsoft docs demonstrate using an example like so:

var blogs = context.Blogs
        .Include(blog => blog.Posts)
            .ThenInclude(post => post.Author)
                .ThenInclude(author => author.Photo)
        .ToList();

Is there a way to do this using the:

Abp.Application.Services.IRepository<TEntity, TPrimaryKey>?

I can already see the IQueryable<TEntity> GetAllIncluding method but I need to fetch deeper than just the next level down.


Solution

  • From the article on Developing a Multi-Tenant SaaS Application with ASP.NET Core:

    public async Task<EventDetailOutput> GetDetailAsync(EntityDto<Guid> input)
    {
        var @event = await _eventRepository
            .GetAll()
            .Include(e => e.Registrations)
                .ThenInclude(r => r.User)
            .Where(e => e.Id == input.Id)
            .FirstOrDefaultAsync();
    
        // ...
    }
    

    Abstracting ThenInclude behind IRepository was explored, but found to be impractical: