如何在 Repository 模式中实现 SelectMany

How to Implement SelectMany in Repository Pattern

我想在通用存储库模式中实现 SelectMany() 查询 我的代码如下所示:

 var query = ctx.Storehouse.Where(x => x.Id == getId)
                    .SelectMany(x => x.Products).Select(x => new
                    {
                        x.Id,
                        .
                        ...
                    }).ToList();

我需要更改以下函数的参数:

public virtual async Task<ICollection<TEntity>> ListOfFoo<TResult>(
        Expression<Func<TEntity, bool>> condition01,
        Expression<Func<TEntity, TResult>> condition02,
        Expression<Func<TEntity, TResult>> condition03)
    {
        return await Dbset.Where(condition01).SelectMany(condition02).Select(condition03).ToListAsync();
    }

并得到如下所示的错误:

public Task<ICollection<TResult>> ListOfFooAsync<TEntity1, TEntity2, TResult>(
            Expression<Func<TEntity1, bool>> condition01,
            Expression<Func<TEntity1, IEnumerable<TEntity2>>> condition02,
            Expression<Func<TEntity2, TResult>> condition03) where TEntity1:class
        {
            return _context.Set<TEntity1>()
                           .Where(condition01)
                           .SelectMany(condition02)
                           .Select(condition03)
                           .ToListAsync();
        }

用法:

var list = await ListOfFooAsync<User, Category, CustomType1>(
            user => user.Id > 1, user => user.Categories, category => new CustomType1
            {
                Id = category.Id
            });