Paging implementation

Hi @mythz,

in 2013 Michael West wrote something about creating a Paging class and he wrote a draft on Google Groups. I have searched the wiki and found nothing regarding to it…

Did you ever implement such QueryBase<T> and/or PagedResult<T> ?

Well we have AutoQuery now which has support for paging built-in is that what you mean?

If you don’t want to use AutoQuery you may still be able to re-use the IQuery, QueryBase Types which contain Skip/Take properties used for paging.

Was looking into make an easier way to implement Paging in a service call…

did this today:

public class ProductSearchList : IHavePaging
    public IEnumerable<Product> Collection { get; set; }

[Route("/search/products/", "GET")]
public class ListSearchProducts : ICanPage, IReturn<ProductSearchList>
    public ListSearchProducts()
        RedeemProducts = false;

    public bool RedeemProducts { get; set; }
    public int? ShopId { get; set; }
    public int? PortalId { get; set; }

using a simple

public class ICanPage
    public ICanPage()
        Page = 0; Items = 25;
    public int Page { get; set; }
    public int Items { get; set; }

public class IHavePaging
    public int TotalRecords { get; set; }
    public int CurrentPage { get; set; }
    public int ItemsPerPage { get; set; }

and I populate it with what needs to pass back…

    public static ProductSearchList ToProductSearchList(this ProductList products, int page, int itemsPerPage)
        var r = new ProductSearchList();

        if (products.Giftcards == null || !products.Giftcards.Any())
            return r;

        // paging
        var totalItem = products.Giftcards?.Count();
        r.TotalRecords = totalItem.Value;
        r.ItemsPerPage = itemsPerPage;
        r.CurrentPage = page;

        // mapping
        r.Collection = products.Giftcards
                            .Skip(page * itemsPerPage)
        return r;

not a very ellegant solution, but was in a rush, so now that I’m back home, was trying to find a better way to do the same… and then I found that post from back in 2013…

Hard to know what else to recommend, we also have AutoQuery Data which provides an Auto Queryable interface over In Memory .NET Collections. Since it’s effortless, I’d look at AutoQuery first to see if it does what you need, otherwise fallback to a manual impl if it doesn’t.

1 Like