public static void Configure <T>(this ISupportPaging grid,
                                         IQueryable <T> query,
                                         Func <int> totalRowCount,
                                         int pageSize = 100)
        {
            ValidateInput(grid, query, totalRowCount, pageSize);

            grid.PageSize = pageSize;

            grid.OnGotoFirst = () => grid.SetDataSource(First, query);

            grid.OnGotoPrev = () => grid.SetDataSource(Prev, query);
            grid.OnGotoNext = () => grid.SetDataSource(Next, query);
            grid.OnGotoLast = () => grid.SetDataSource(Last, query);

            if (grid.TotalPages == null)
            {
                //local copy to avoid possible multiple enumerations.
                var total = totalRowCount();
                //
                grid.TotalPages = () => CalculatePages(grid, total);
            }

            //Goes to the first page.
            grid.SetDataSource(First, query);
            grid.CleanUp = () =>
                           PagingCache.Remove(grid);//<= to avoid memory  leaks.

            if (grid.EndConfigure != null)
            {
                grid.EndConfigure();
            }
            grid.Configured = true;
        }
        public static void Search <T>(this ISupportPaging grid,
                                      IQueryable <T> source,
                                      Func <T, bool> criteria)
        {
            if (!grid.Configured)
            {
                throw new InvalidOperationException(
                          "You have to configure the grid first. Take a look at the configure method");
            }

            PagingCache.Invalidate();
            grid.SetDataSource(First, source.Where(criteria).AsQueryable());
        }
 static IEnumerable <T> GetPage <T>(this ISupportPaging grid,
                                    IQueryable <T> dataSource)
 {
     return(PagingCache.CacheAndReturn(grid, dataSource));
 }
        //

        private static IEnumerable <T> InternalSearch <T>(this ISupportPaging grid, IQueryable <T> dataSource)
        {
            grid.CurrentPage = 0;
            PagingCache.Invalidate();//maybe this is not the best way to go....
            return(grid.GetPage(dataSource));
        }