Best way to use LINQ query & Gridview paging when dealing with large recordsets.
I have a gridview on a page which is populated by a LINQ query in the code behind. Nothing fancy but, does use pagination (using the pageIndex changed event).
All works fine but, ran into a problem when running in our dev environment due to there being alot of data in the DB.
So my question is given that the LINQ is only enumerated on databinding and the gridview has a page size of 20, does the LINQ fetch all of the records each time its databound? and how would you deal with binding the results of a LINQ query to a gridview when dealing with a large number of reco开发者_如何学Crds?
Here is the solution in which I have created the custom grid whcih support linq query and paginging : LINQ TO SQL GridView (Enhanced Gridview)
I suggest using two methods:
Get the current page of results you want to view by using the
Skip()
andTake()
methods on theIQueryable<T>
result set. You would pass in yourpageIndex
andmaximumRows
values to determine the value to send intoSkip()
(e.g.pageIndex * maximumRows
).The second method to use is to get the count of total possible records using the
Count()
method on the same exact LINQ query. This way you can get the count without getting all the rows (massive amounts of data).
Hope that helps.
精彩评论