优化分页和使用具有EnableCaching = true的ObjectDataSource进行排序 [英] Optimize Pagination & Sorting with ObjectDataSource having EnableCaching = true

查看:84
本文介绍了优化分页和使用具有EnableCaching = true的ObjectDataSource进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有Linq-To-SQL类的ODS(ObjectDataSource)备份来填充页面上的Gridview.

I'm using an ODS(ObjectDataSource) backed-up with a Linq-To-SQL class to populate Gridview on my page.

考虑到性能-我已禁用Gridview的Viewstate并启用了ODS中的缓存.

Considering the performance - I've disabled the Viewstate of the Gridview and enabled caching in the ODS.

除此之外,我还优化了Linq-to-SQL类中的Search方法以使用.skip& .take方法仅获取分页"记录.

Apart from this, I've also optimized the Search method in the Linq-to-SQL class to use the .skip & .take methods to fetch only a 'pageful' of records.

现在,问题在于,由于缓存ODS而无法单独对记录集进行排序".如该线程中所述:

Now, the problem is that due to caching the ODS is unable to 'sort' the record set on its own. As detailed on this thread:

在"Custome分页"和排序"中启用缓存时,GridView排序不起作用

人们建议使用自定义排序并实现比较器",但我认为这会损害我的性能优势.

People recommend to use custom sort and implement 'Comparer' but I believe this ruins my performance benefits.

http://forums.asp.net/t/1344883.aspx

我已经准备好进行排序时的DB行程了,但是如何在打开缓存时将其分开呢?

I'm ready to make a DB-trip while sorting but how to separate that when the Caching is turned-on?

仅供参考,我已经有了一个AJAX更新面板,其中包含此Gridview(EnableViewstate = false)和ODS(EnableCaching = true).希望我走在正确的道路上...建议受到赞赏.

FYI, I already have an AJAX update panel in which I've got this Gridview (EnableViewstate = false) and ODS (EnableCaching=true). Hope I'm on the right path ... suggestions are appreciated.

我必须使用自定义排序"在应用程序端执行排序(这是添加额外的方法以对通用对象集合进行排序).此解决方案不可接受,因为它要求我从数据库中提取所有记录,然后对它们进行排序!

I've to perform sorting on app side using the 'Custom-sort' (that is add extra methods to enable sorting on a generic collection of objects). This solution was not acceptable because it demanded that I pull ALL the records from the DB and then perform sorting on them!

首先,我不认为应用程序可以比DB更好/更快地进行排序.其次-这破坏了我因优化分页而获得的整体性能优势-我正在使用.skip()和.take()LINQ方法来仅获取分页"记录.

Firstly, I don't believe app can do better/faster sorting then DB. And secondly - this ruins the whole performance benefit that I'm getting due to optimized pagination - I'm using .skip() and .take() LINQ methods to fetch only a 'pageful' of records.

好吧,最后我不得不发明一种解决方法 我自己的.它可能仅限于我的种类 场景,但可以肯定的是 更容易,也保留了 分页优化为 以及数据缓存.

Well, finally I had to invent a fix of my own. It might be limited to my kind of scenario but for sure its much easier and also preserves the optimization of both pagination as well as data-caching.

我的解决方案: 我点击了Gridview的排序"事件.如果我允许ODS尝试对缓存的数据自行进行排序,则会触发自定义排序"错误.取而代之的是,现在我手动执行排序并取消排序事件. 为此-我只需要在ODS中使'orderBy'参数显式并将其设置为Gridview的'Sorting'事件中的新sort-expression.这将刷新网格,最后我将执行以下操作:

MY SOLUTION: I've tapped the Gridview's 'Sorting' event. The 'custom-sort' error triggers if I allow the ODS to try to do the sorting on its own on the cached data. Instead of that, now I perform sorting manually and cancel the sorting-event. For this - I just have to make the 'orderBy' parameter explicit in ODS and set it to the new sort-expression in Gridview's 'Sorting' event. This will refresh the Grid and at the end I do:

odsOrganization.SelectParameters["orderBy"].DefaultValue = GetSortExpr(e.SortExpression);
...
e.Cancel = true;

    • 这告诉ODS取消排序 (我之前已经执行过 取消活动-如上).它的 就像我在欺骗ODS并处理 在后台排序.谢谢你 对于ODS,它感觉到 "SelectParameters ["orderBy"]具有 更改并执行一次选择 再次.我以前的排序 自动存储在 'odsOrganization.SelectParameters ["orderBy"].DefaultValue' 我可以在以后使用 迭代.

      this tells the ODS to cancel sorting (which I already performed before canceling the event - as above). ITs like I'm cheating the ODS and handling the sorting in background. And thanks to ODS that it senses that the 'SelectParameters["orderBy"]' has changed and performs a select once again. I The previous sort automatically gets stored in the 'odsOrganization.SelectParameters["orderBy"].DefaultValue' which I can use in sub-sequent iterations.

    • 我仍在测试这一点,但令人惊讶的是,仅通过更新参数的DefaultValue ODS即可返回数据.这将保留缓存,直到用户执行排序为止(它从缓存中获取数据以进行其他操作)并返回到DB进行排序.希望它对我有用!

      I'm still testing this one but its amazing that just by updating the parameter's DefaultValue ODS goes back to fetch the data. This preserves the cache until the user performs sort (it takes data from cache for other operations) and goes back to the DB to sort. Hope its going to work for me!

      推荐答案

      这项工作可行吗?

      查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆