Skip to content

X.PagedList.EF

Andrew Gubskiy edited this page Jul 8, 2024 · 5 revisions

X.PagedList.EF contains custom PagedList which support lambda function for EF queries.

Installation

Install X.PagedList.EF from NuGet.

How use library

If you're using Entity Framework Core, you can switch to using lambda expressions with Skip and Take. The benefit here is that LINQ+EF will recognize your Skip and Take values as parameters that can be passed to a compiled query.

var records = db.SalesOrders.Skip(() => pos).Take(() => size);

LINQ for EF will compile your query once and just re-execute it on each request, passing the new values for pos and size. It's a trivial change to your syntax but it can shave 10 percent off the time it takes your repeated query to run.

private void InitSubset(IOrderedQueryable<T> superset, int pageNumber, int pageSize)
{
    var itemsToSkip = (pageNumber - 1) * pageSize;

    // add items to internal list
    var items = superset
        .Skip(() => itemsToSkip)
        .Take(() => pageSize)
        .ToList();

    Subset.AddRange(items);
}

More information you can find here

Clone this wiki locally