2

有没有办法在不获取所有项目的情况下获取有序查询的索引?

我的代码似乎是网络流量的杀手:

 public virtual async Task<int> GetIndexOfQueryable<TOrderKey>(Expression<Func<TEntity, bool>> whereExp, Predicate<TEntity> findIndexExp, Expression<Func<TEntity, TOrderKey>> orderbyExp, bool descending)
    {
        IQueryable<TEntity> query = whereExp != null ? DbSet.Where(whereExp) : DbSet.AsQueryable();
        if (orderbyExp != null)
            query = !descending ? query.OrderBy(orderbyExp) : query.OrderByDescending(orderbyExp);
        return (await query.ToListAsync()).FindIndex(findIndexExp);
    }
4

0 回答 0