コード例 #1
0
        public IQueryable <TEntity> GetMany(ISpecification <TEntity> spec)
        {
            // 获取包含所有基于表达式的包含的可查询项
            var queryableResultWithIncludes = spec.Includes
                                              .Aggregate(_dbContext.Set <TEntity>().AsQueryable(), (current, include) => current.Include(include));

            // 获取包含所有基于表达式的include的可查询项,修改可查询项以包含任何基于字符串的include语句
            var secondaryResult = spec.IncludeStrings
                                  .Aggregate(queryableResultWithIncludes,
                                             (current, include) => current.Include(include));

            // 使用规范的条件表达式返回查询的结果
            return(secondaryResult
                   .Where(spec.Criteria)
                   );
        }
コード例 #2
0
 public Repository(STSysContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _dbSet     = _dbContext.Set <TEntity>();
 }