开发者

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:

  1. Get the current page of results you want to view by using the Skip() and Take() methods on the IQueryable<T> result set. You would pass in your pageIndex and maximumRows values to determine the value to send into Skip() (e.g. pageIndex * maximumRows).

  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜