Getting RowCount For IQueryable not IQueryable<T>

48 Views Asked by At

Long story short, we have a C# WebApi that provides mapped instances from our DAL into DTOS.

Each controller exposes a IEnumerable<T> Get()

I have a test that finds all the controllers, and call this get method.

This flushes out any mapping errors that only occur on execution.

A while I noticed that to be sure you had to actually execute the enumeration otherwise the the mapping never takes place.

So I have this code

if (results is IEnumerable enumerable)
{
    var counter = enumerable.Cast<object>().Count();
    Trace.Write($"{counter} results found.");
}

This executes the cast (which invokes the mapping) and gives me a count for output reasons.

This worked until the result set got massive - it nows just times out.

Most of my IEnumerables are actually IQueryable underneath

I need a way to Take(10) on an IQueryable that can work on reflected data/executed types. This will let the mapping work but on a smaller data set.

Help!

0

There are 0 best solutions below