存储库查询加载相关数据

Repository Query Loading Related Data

Microsoft 文档使用如下示例进行演示:

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

有没有办法使用:

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

我已经可以看到 IQueryable<TEntity> GetAllIncluding 方法,但我需要获取比下一层更深的内容。

来自 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();

    // ...
}

IRepository 背后的抽象 ThenInclude 已探索,但发现不切实际:

您也可以这样做:

public async Task<EventDetailOutput> GetDetailAsync(EntityDto<Guid> input)
{
    var @event = await _eventRepository
        .GetAllIncluding(e => e.Registrations, e => e.Registrations.User)
        .FirstOrDefault(e => e.Id == input.Id);

    // ...
}

唯一的限制是,由于 Intellisense 中的错误,您不能在包含集合后包含第二层:Include->ThenInclude for a collection