public Task <int> CountAsync(ISpecification <TEntity> spec, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (spec == null)
            {
                throw new ArgumentNullException(nameof(spec));
            }

            var query = spec.AddPredicates(DbContext.Set <TEntity>().AsQueryable());

            return(query.CountAsync(cancellationToken));
        }
        public virtual Task <bool> ExistsAsync(ISpecification <TEntity> spec, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (spec == null)
            {
                throw new ArgumentNullException(nameof(spec));
            }

            var query = DbContext.Set <TEntity>().AsQueryable();

            query = spec.AddPredicates(query);

            return(query.AnyAsync(cancellationToken));
        }
        private IQueryable <TEntity> BuildGetQuery(ISpecification <TEntity> spec)
        {
            if (spec == null)
            {
                throw new ArgumentNullException(nameof(spec));
            }

            var query = DbContext.Set <TEntity>().AsQueryable();

            query = spec.AddPredicates(query);
            query = spec.AddSorting(query);
            query = spec.AddEagerFetching(query);

            return(query);
        }