sarat
sarat

Reputation: 11160

Implement Pagination with LINQ (C#)?

I am a newbie with Database Applications.

I would like to implement pagination with lower memory footprint. The application is connected to MS SQL Server 2008 R2 DB.

The table I have consists of thousands of records and the application can query the records with given criteria.

The current implementation using LINQ-SQL for querying and the whole data will be returned the application. If the query returns too much of results, this could exhaust the process memory. Hence I would like to implement this as pages.

I came across some stored procedures across the web which can paginate the data.

I am not sure if the standard pagination can help me to meet the following requirements

Upvotes: 3

Views: 3036

Answers (2)

Asif Mushtaq
Asif Mushtaq

Reputation: 13150

Pagination is not a problem using Linq you can do pagination using Take() and Skip()

var page = list.Skip((pageNo - 1) * pageSize)
               .Take(pageSize)

Upvotes: 5

Pranay Rana
Pranay Rana

Reputation: 176956

Grid view control has the following features:

  • Linq 2 SQL support
  • Custom paging using Linq 2 SQL
  • Display sorting direction
  • Dropdown in the pager to adjust the number of records in a page

LINQ TO SQL GridView (Enhanced Gridview)

Upvotes: 3

Related Questions