'Implementing IQueryable.Count

I'm working on an IQueryable provider. In my IQueryProvider I have the following code:

public TResult Execute<TResult>(Expression expression)
{
    var query = GetQueryText(expression);

    // Call the Web service and get the results.
    var items = myWebService.Select<TResult>(query);

    IQueryable<TResult> queryableItems = items.AsQueryable<TResult>();
    return (TResult)queryableItems;
}

GetQueryText does all the leg work and works out the query string for the expression tree. This is all working well, so Where, OrderBy and Take are sorted. The webservice supports a count query using the following:

int count = myWebService.Count(query);

But I can't get my head round where I put this in the IQueryable or IQueryProvider.

I've basically worked from reading tutorials and open source examples, but can't seem to find one that does Count.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source