检索结果并将其显示在 Telerik 网格中的时间过长。
我有一个 MVC 应用程序,需要在其中显示 3 个表中的数据。我正在使用实体模型。其中,在 2 中我建立了关联:用户和支付表。
第三个表 month_
每月创建一次,用于存储杂志发送给的用户。表名 month_
是通过选择月份动态生成的,因此为了获取我使用 ExeuteStoreQuery 的数据。对于少量数据,列表速度很快,但对于大量数据,列表非常慢。
现在我创建了一个类来绑定到网格,它将包含 3 个表中要显示的所有字段。 但是在这里,当我获得大约 12000 的大量数据时,需要大约 30 分钟来完成循环并将数据分配给类对象,然后添加到最终绑定到 Telerik 网格的结果列表中。
我特此使用链接附加示例代码。有没有直接的方法将连接表的查询结果绑定到网格,而不是通过循环并为模型类准备列表,我认为这会节省时间。 使用 Executestorequery 准备列表的代码块位于函数 GetuserList() 下。
foreach (var r in result)
{
Result objresult = new Result();
var paymentresult = from sub in dtpayment.AsEnumerable() where sub.Field<int>("user_id") == r.user_id select sub;
if (paymentresult.Count() > 0)
{
objresult.amount_paid = paymentresult.FirstOrDefault().Field<decimal>("amount_paid");
objresult.magzine_id = paymentresult.FirstOrDefault().Field<int>("magzine_id");
}
objresult.address=r.address;
objresult.email=r.email;
objresult.name=r.name;
objresult.user_id=r.user_id;
objresult.month= smonth;
lstresult.Add(objresult);
}
当我使用 ExceuteStoreQuery 时,for 循环的代码块花费了很多时间。 但我观察到,只需使用 LINQ 查询连接用户和付款表即可获取所有 12000 条记录,即不涉及月份表,结果显示得更快。 那么,您能建议任何方法来提高我的应用程序的性能吗?
还包括数据库结构和示例代码。 以下是示例的链接
苏普里亚
I have a MVC application in which I need to display the data from 3 tables. I am using entity model for it. Out of these, in 2 I have made the association:users and payment table.
And 3rd table month_<monthid>
is created every month to store the users to whom the magazine is sent. The table name month_<monthid>
is generated dynamically by selecting the month so in order to fetch the data I have used ExeuteStoreQuery. For small amount of data the listing is fast but for large amount it is very slow.
Now I have created a class to bind to grid which will include all the fields from the 3 tables to display.
But here when I am getting the large volume of data about 12000 then it is taking about 30 min to go through the loop and assigning the data to the class object and then adding to the list of the result which is finally binded to telerik grid.
I am hereby attaching the sample code using a link. Is there any direct way to bind the query result of joined tables to grid instead of going through the loop and preparing the list for the model class I think that will save time.
The code block of preparing the list using the Executestorequery is under the function GetuserList().
foreach (var r in result)
{
Result objresult = new Result();
var paymentresult = from sub in dtpayment.AsEnumerable() where sub.Field<int>("user_id") == r.user_id select sub;
if (paymentresult.Count() > 0)
{
objresult.amount_paid = paymentresult.FirstOrDefault().Field<decimal>("amount_paid");
objresult.magzine_id = paymentresult.FirstOrDefault().Field<int>("magzine_id");
}
objresult.address=r.address;
objresult.email=r.email;
objresult.name=r.name;
objresult.user_id=r.user_id;
objresult.month= smonth;
lstresult.Add(objresult);
}
This code block of for loop is taking very time where I am using ExceuteStoreQuery.
But I have observed that simply by joining the users and payment table using LINQ query to get all the 12000 records i.e no involvement of month table the result is appearing faster.
So,can you suggest any way to improve the performance of my application?
Also include the database structure with the sample code.
Below is the link to sample
supriya
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
世界上没有人愿意看到 12,000 条记录。您应该考虑实现分页和分页。搜索功能。
Nobody in the world wants to see 12,000 records. You should look at implementing paging & searching functionality.