When I have an IQueryable<T> (generic) I can use the Take method to return only N records from the result set returned by the query.
When I’m using a simple non-generic IQueryable, Take method is not available. Is there an other way to achieve the same result as the Take method?
UPDATE: as Richard pointed, another question solves this problem. In my case, the necessary code was even simpler then the code proposed by Jon Skeet in the other question. That’s my final code:
dynamic tempQuery = originalQuery;
finalQuery = Queryable.Take(tempQuery, numRecords);
Use this extension method:
You can achieve a similar effect with the various extension methods defined on
QueryablelikeSkipand others, provided you match the method signatures and provide well-formed expression trees.