views:

13

answers:

1

Given the following...

int maxResults = 25;
string code = "Thailand";

var q = from i in images where i.component_code == code select i;

var images = q.OrderByDescending(x => x.image_rating).Take(maxResults);

if (images.Count() > 0)
{
    ...

    lblResult = string.Format("Viewing {0} Images Of A Possible {1}", images.Count(), ?);
}

How do I get the potential total number of images that would have been returned if Take() had not been used

+4  A: 

Can't you use q.Count() for this?

Kristof Claes
performace wise, at what point does linq hit the database and does it hit the database twice, once to get the count and second to get the subset of results?
Nick Allen - Tungle139
You will have two queries to the database, but if you weren't using LINQ (LINQ to SQL I guess) how would do this? You need two queries.
Steven