GreenEyedAndy
GreenEyedAndy

Reputation: 1525

strange behavior getting count of records

I know the fact that I can't get more than 128 records by one query and that this can be extended to 1024 if I use .Take(1024) but I have a new problem with this Code on the sample Database:

var albumCount = session.Query<Album>().Count();
Console.WriteLine(albumCount);          // 246 as expected?!?

var somemoredata = session.Query<Album>();
Console.WriteLine(somemoredata.Count());    // 246 but it sould be 128
int cnt = 1;
foreach (var album in somemoredata)
{
   Console.WriteLine(cnt++.ToString() + " " + album.Id);  // repeats 128 counts
}

How can this be? The Count of somemoredata is 246, but the foreach writes 128 Lines?!?

Where is the error?

Upvotes: 1

Views: 148

Answers (1)

Fitzchak Yitzchaki
Fitzchak Yitzchaki

Reputation: 9163

Take is doing paging for you, which is part of the save by default principle. But Count should always give the actual count of the documents for that query.

This will ensure that you can:

  1. Display an indication that the data shown is just a slice of the information. (Page 1 of X).
  2. Let you know that we need to do paging, when you need to.

Upvotes: 2

Related Questions