将gridview与大数据绑定时的性能问题
问题:我试图从数据库中获取大量条目并将其绑定到 gridview,这使得我的网站性能非常低。 我所使用的:我已经索引了搜索时主要涉及的参数。此外,我还在会话中存储数据库返回的查询,并在分页时使用它,而不是再次访问数据库。
我想要什么?有什么方法可以让我们从数据库中检索网格页面大小的条目。我的网格页面大小是 10。因此 10 个条目将极大地提高网站的性能。由于数据网格中有许多字段,获取它们需要时间。那么有没有类似这样的解决方案呢?
查询代码:
R1.DBLinqRDataContext objDB = new R1.DBLinqRDataContext();
return ( from p in (from a in objDB.table1
orderby a.date descending
join i in objDB.table2
on a.ID equals i.ID
where ((SqlMethods.Like(a.Location, "%" + loc + "%")) && (Category != String.Empty ? (Category == "1" ? a.Func < 50 : a.Func > 50) : (SqlMethods.Like(a.loc, "%" + loc + "%"))))
select a) join r3 in objDB.table3 on p.ID equals r3.CompanyID select p).Distinct().ToList();
有帮助吗?
如果有更多细节请询问...谢谢
Problem: i am trying to fetch huge number of entries from the database and binding it to the gridview which is making my site performance very low.
what i have used: i have indexed the parameters which are mainly involved while searching. Also i am stroing the database returned queries in session and using it while paging, instead of hitting the database again.
What i want? is there any way we can just retrieve entries from the database for the page size of the grid. my grid page size is 10. So 10 entries would higly enhance the performance of the site. Since there are numerous fields in the datagrid and fetching them takes time. So is there any solution like this?
code for the query:
R1.DBLinqRDataContext objDB = new R1.DBLinqRDataContext();
return ( from p in (from a in objDB.table1
orderby a.date descending
join i in objDB.table2
on a.ID equals i.ID
where ((SqlMethods.Like(a.Location, "%" + loc + "%")) && (Category != String.Empty ? (Category == "1" ? a.Func < 50 : a.Func > 50) : (SqlMethods.Like(a.loc, "%" + loc + "%"))))
select a) join r3 in objDB.table3 on p.ID equals r3.CompanyID select p).Distinct().ToList();
Any assist?
if any more details please ask....thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于另一个答案的观点,执行 [query].Skip(x).Take(y) 效果很好,但是当您进行跳过并接受调用时,请检查您正在调用 IQueriable 版本而不是 IEnumerable 版本。
如果您调用 IQueriable 版本,那么它将合并到查询中。 IEnumerable 将执行查询,然后在内存中运行分页,您将失去所有性能提升。
To the other answer's point, doing a [query].Skip(x).Take(y) works great, but check when you make the skip and take calls that you're calling the IQueriable version and not the IEnumerable version.
If you call the IQueriable version then it gets incorporated into the query. IEnumerable will execute the query and then run the paging in memory and you loose all your performance gains.
尝试阅读此内容
Try reading through this