internal Task <EntityQueryResult <TEntity> > SearchAsync(
            IEntitySearchDescriptor <TEntity> searchDescriptor,
            Func <TStore, IQueryable <TEntity>, Task> retrieveFiltersAsync,
            Func <TStore, IQueryable <TEntity>, Task> refineFiltersAsync)
        {
            ThrowIfDisposed();
            if (SupportsQueryableEntity)
            {
                return(SearchInternalAsync(QueryableEntityStore.Entities, searchDescriptor, retrieveFiltersAsync, refineFiltersAsync));
            }

            throw new NotImplementedException();
        }
        private async Task <EntityQueryResult <TEntity> > SearchInternalAsync(
            IQueryable <TEntity> entities,
            IEntitySearchDescriptor <TEntity> searchDescriptor,
            Func <TStore, IQueryable <TEntity>, Task> retrieveFiltersAsync,
            Func <TStore, IQueryable <TEntity>, Task> refineFiltersAsync)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            if (SupportsEagerLoadingEntity)
            {
                entities = EagerLoadingEntityStore.EagerLoad(entities);
            }

            var result = new EntityQueryResult <TEntity>();

            entities          = PreFilter(entities, searchDescriptor);
            result.TotalCount = await Count(entities);
            await retrieveFiltersAsync(EntitiesSearchStore, entities);

            entities             = Filter(entities, searchDescriptor);
            result.FilteredCount = await Count(entities);
            await refineFiltersAsync(EntitiesSearchStore, entities);

            entities = Sort(entities, searchDescriptor);

            result.Results = Page(entities, searchDescriptor);

            if (SupportsExplicitLoadingEntity)
            {
                result.Results = result.Results.ToList().AsQueryable();
                await ExplicitLoadingEntityStore.ExplicitLoadAsync(result.Results, CancellationToken);
            }

            return(result);
        }