Oct 20, 2008 / nhibernate ~ .net ~ linq
Returning IQueryable rather than List

Usually when I write repositories, I end up with code like this:

IList<Order> orders = repos.FindOrdersByStatus(OrderStatus.Packed);

One problem with this is that orders might contain 10,000 records, and I don't really want to pull all that back from the database in one go. What I think I want is this:

IList<Orders> orders = repos.FindOrdersByStatus(OrderStatus.Packed)
                                                  .Skip10)
                                                  .Take(10)
                                                  .ToList();

FindOrderByStatus is returning an IQueryable rather than IList. The beauty is that every query can be paginated for "free" - no need to modify repository method signatures with pagination fluff. And, pagination is executed in the database yet controlled by any client using the repository class.

Is anyone doing this?


You may also like...