Beispiel #1
0
        /// <summary>
        /// Given a queryable and a queryableEvaluator realizes the query asynchronously
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IQueryableEvaluator</param>
        /// <param name="cancellationToken">CancelationsToken</param>
        /// <returns>Data resulting from the query</returns>
        public virtual async Task <TResult> RunAsync(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator, string[] includes, CancellationToken cancellationToken = default)
        {
            var processedQuery = this.RunQuery(queryable);
            var result         = await this.GenerateResultAsync(processedQuery, evaluator, cancellationToken);

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Given a queryable and a queryableEvaluator realizes the query
        /// </summary>
        /// <param name="queryable">IQueriable</param>
        /// <param name="evaluator">IQueryableEvaluator</param>
        /// <returns>Data resulting from the query</returns>
        public virtual TResult Run(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator)
        {
            var processedQuery = this.RunQuery(queryable);
            var result         = this.GenerateResult(processedQuery, evaluator);

            return(result);
        }
 public GenericRepository(AppDbContext dbContext,
                          IQueryableEvaluator evaluator,
                          ISpecificationBuilder specificationBuilder)
 {
     _dbContext                = dbContext;
     this.Evaluator            = evaluator;
     this.SpecificationBuilder = specificationBuilder;
 }
Beispiel #4
0
        /// <summary>
        /// Given a Queryable and a QueryableEvaluator realizes the query asynchronously
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IQueryableEvaluator</param>
        /// <param name="cancellationToken">CancelationToken</param>
        /// <returns>Data resulting from the query</returns>
        public override async Task <IPagedQueryResult <TResult> > RunAsync(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator, CancellationToken cancellationToken = default)
        {
            queryable  = this.RunQuery(queryable);
            this.count = await evaluator.CountAsync(queryable, cancellationToken);

            queryable = this.Sort(queryable);
            queryable = this.Paginate(queryable);
            var result = await this.GenerateResultAsync(queryable, evaluator, cancellationToken);

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Given a Queryable and a QueryableEvaluator realizes the query
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IQueryableEvaluator</param>
        /// <returns>Data resulting from the query</returns>
        public override IPagedQueryResult <TResult> Run(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator)
        {
            queryable  = this.RunQuery(queryable);
            this.count = evaluator.Count(queryable);
            queryable  = this.Sort(queryable);
            queryable  = this.Paginate(queryable);
            var result = this.GenerateResult(queryable, evaluator);

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Generates the query asynchronously and returns data in <typeparamref name="TResult"/>
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IqueryableEvaluator</param>
        /// <param name="cancellationToken">CancelationToken</param>
        /// <returns>Data resulting from the query</returns>
        protected override async Task <IPagedQueryResult <TResult> > GenerateResultAsync(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator, CancellationToken cancellationToken = default)
        {
            var materialized = this.Materialize(queryable);
            var values       = await evaluator.ToArrayAsync(materialized, cancellationToken);

            return(new PagedQueryResult <TResult>(values, this.Take, this.Skip, this.count));
        }
Beispiel #7
0
        /// <summary>
        /// Generates the query and returns data in <typeparamref name="TResult"/>
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IQueryableEvaluatos</param>
        /// <returns>Data resulting from the query</returns>
        protected override IPagedQueryResult <TResult> GenerateResult(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator)
        {
            var materialized = this.Materialize(queryable);
            var values       = evaluator.ToArray(materialized);

            return(new PagedQueryResult <TResult>(values, this.Take, this.Skip, this.count));
        }
        /// <summary>
        /// Given a Queryable and a QueryableEvaluator realizes the query asynchronously
        /// </summary>
        /// <param name="queryable">IQueryable</param>
        /// <param name="evaluator">IQueryableEvaluator</param>
        /// <param name="cancellationToken">CancelationToken</param>
        /// <returns>Data resulting from the query</returns>
        public override async Task <IPagedQueryResult <TResult> > RunAsync(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator, string[] includes, CancellationToken cancellationToken = default)
        {
            queryable  = this.RunQuery(queryable);
            this.count = await evaluator.CountAsync(queryable, cancellationToken);

            queryable = this.Sort(queryable);
            queryable = this.Paginate(queryable);
            if (includes != null)
            {
                foreach (string include in includes)
                {
                    queryable = queryable.Include(include);
                }
            }
            var result = await this.GenerateResultAsync(queryable, evaluator, cancellationToken);

            return(result);
        }
Beispiel #9
0
 /// <summary>
 /// Abstract method to be implemented in the inheriting classes that generates asynchronously the query result <typeparamref name="TResult"/>
 /// </summary>
 /// <param name="queryable">IQueryable</param>
 /// <param name="evaluator">IQueryableEvaluator</param>
 /// <param name="cancellationToken">CancelationToken</param>
 /// <returns>Data resulting from the query</returns>
 protected abstract Task <TResult> GenerateResultAsync(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator, CancellationToken cancellationToken = default);
Beispiel #10
0
 /// <summary>
 /// Abstract method to be implemented in the inheriting classes that generates the query result depending on <typeparamref name="TResult"/>
 /// </summary>
 /// <param name="queryable">IQueryable</param>
 /// <param name="evaluator">IQueryableEvaluator</param>
 /// <returns>Data resulting from the query</returns>
 protected abstract TResult GenerateResult(IQueryable <TEntity> queryable, IQueryableEvaluator evaluator);