Paging Support - ADO.NET Entitry Framework and LINQ

What paging support is offered through ADO.NET EF and LINQ?

What does the "first 10" do? Choose a similar view?

A "next 10" Choose?

+4
source share
3 answers

The Take keyword is used to determine how many records should be received. A simple example of the Take keyword below.

Customer List = GetCustomerList ();

var first3Customers = ( from c in customers select new {c.CustomerID, c.CustomerName} ) .Take(4); 

Here we take the first 4 customers for the list provided.

we can also use the where clause to narrow down the list first and then take 4 of them.

 var first3Customers = ( from c in customers where c.Region == "Kol" select new {c.CustomerID, c.CustomerName} ) .Take(4); 

But what if we want to get data between the 4th and 8th record. In this case, we use the skip keyword to skip the number of entries (above) we do not want. Here is an example using the Skip keyword.

 var first3Customers = ( from c in customers where c.Region == "Kol" select new {c.CustomerID, c.CustomerName} ) .Skip(3).Take(4); 

Read more here

+8
source

As others have explained, Take () and Skip () are what you need.

They will break the result set to get the page you need.

You must somehow support the PageIndex and PageSize information so that you can pass them when the query is executed. If your access to data is through a web service, for example, you must pass the index / size along with your filtering criteria, maintaining these values ​​in your client (application or page, if this is a website).

There is no “stateful pager iterator” out of the box if that is what you are looking for ...

In addition, if you are implementing the “standard paging” design, you will need to get the total number of records before limiting your request, which you can do so assuming that your function somehow receives the PageSize and PageIndex parameters:

 var query = ...your normal query here... int totalRecordCount = query.Count(); var pagedQuery = query.Skip(PageIndex*PageSize).Take(PageSize); 
+11
source

If you have nuget in Visual Studio, you can add the PagedList package.

Check out this link on asp.net

0
source

All Articles