在.NET MVC和EF中分页没有回发的大表

时间:2021-06-02 10:18:53

I have a large table with a few million records.

我有一张有几百万条记录的大桌子。

Have got an MVC5 solution and using PagedList.MVC with Entity Framework I have a page showing the paged table with sorting and filters.

有一个MVC5解决方案并使用PagedList.MVC和Entity Framework我有一个页面显示带有排序和过滤器的分页表。

But every filter and page-change operation requires a postback.

但是每个过滤器和页面更改操作都需要回发。

Is there any way to prevent postbacks without pre-loading the entire table into memory?

有没有办法在不将整个表预先加载到内存中的情况下阻止回发?

1 个解决方案

#1


0  

Since you put in your comment you are open to a different solution why don't you do the following:

由于您提交了评论,因此您可以使用不同的解决方案,为什么不执行以下操作:

1) Assuming the large table is in some database. Update your procedure to take in as parameters, the number of rows per page in your gridview, and the current page index you are viewing in the gridview

1)假设大表位于某个数据库中。更新您的过程以作为参数,gridview中每页的行数以及您在gridview中查看的当前页面索引

2) Update the procedure to return only the rows for that specific page the user is on using the parameters above. Also return the total count of rows as an int this way you can calculate how many pages need to be in the gridview. Consider caching this in the session so you only need to query the total count once.

2)使用上述参数更新过程以仅返回用户所在的特定页面的行。同样以int的形式返回行总数,这样您就可以计算gridview中需要的页数。考虑在会话中缓存此内容,因此您只需查询一次总计数。

Doing this will make updating the gridview very fast since the procedure will only return the rows you need to display on the current page.

执行此操作将非常快速地更新gridview,因为该过程将仅返回您需要在当前页面上显示的行。

#1


0  

Since you put in your comment you are open to a different solution why don't you do the following:

由于您提交了评论,因此您可以使用不同的解决方案,为什么不执行以下操作:

1) Assuming the large table is in some database. Update your procedure to take in as parameters, the number of rows per page in your gridview, and the current page index you are viewing in the gridview

1)假设大表位于某个数据库中。更新您的过程以作为参数,gridview中每页的行数以及您在gridview中查看的当前页面索引

2) Update the procedure to return only the rows for that specific page the user is on using the parameters above. Also return the total count of rows as an int this way you can calculate how many pages need to be in the gridview. Consider caching this in the session so you only need to query the total count once.

2)使用上述参数更新过程以仅返回用户所在的特定页面的行。同样以int的形式返回行总数,这样您就可以计算gridview中需要的页数。考虑在会话中缓存此内容,因此您只需查询一次总计数。

Doing this will make updating the gridview very fast since the procedure will only return the rows you need to display on the current page.

执行此操作将非常快速地更新gridview,因为该过程将仅返回您需要在当前页面上显示的行。