存储库查询加载相关数据

时间:2018-03-09 06:07:24

标签: aspnetboilerplate

微软文档使用如下示例演示:

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方法,但我需要更深入地获取更深层次的内容。

2 个答案:

答案 0 :(得分:4)

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

    // ...
}

ThenInclude后面提取IRepository进行了探索,但发现不切实际:

答案 1 :(得分:0)

你也可以这样做:

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