Retrieving entire data collection from a RavenDB

前端 未结 6 935
囚心锁ツ
囚心锁ツ 2021-02-01 21:55

I have a requirement where I need to fetch the entire data collection Users from RavenDB and compare the retrieved result set with another set of data. There are cl

6条回答
  •  孤街浪徒
    2021-02-01 22:46

    I honestly prefer the following function:

        public IEnumerable GetAll()
        {
            List list = new List();
    
            RavenQueryStatistics statistics = new RavenQueryStatistics();
    
            list.AddRange(_session.Query().Statistics(out statistics));
            if (statistics.TotalResults > 128)
            {
                int toTake = statistics.TotalResults - 128;
                int taken = 128;
                while (toTake > 0)
                {
                    list.AddRange(_session.Query().Skip(taken).Take(toTake > 1024 ? 1024 : toTake));
                    toTake -= 1024;
                    taken += 1024;
                }
            }
    
            return list;
        }
    

    []'s

提交回复
热议问题