大型查询如何在C#/ASP.NET MVC 4部分中返回结果 [英] Large query how to return results back in sections C#/ASP.NET MVC 4

查看:248
本文介绍了大型查询如何在C#/ASP.NET MVC 4部分中返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用ASP.NET MVC 4编写的应用程序.我需要从使用oledbdatareader访问的表中返回较大的结果.

I have an application written in ASP.NET MVC 4. I have a requirement to return large results from a table accessed with oledbdatareader.

我正在使用AJAX返回包含列表的JsonResult对象:List<TableRow>

I am using AJAX to return a JsonResult object that contains a List: List<TableRow>

我不了解的是,如果我处于DataReader循环中

What I do not understand is, if I am in the DataReader loop

using (OleDbDataReader reader = command.ExecuteReader())
{
   while (reader.Read())
   {
       names.Add(Convert.ToString(reader[0]));
   }
}

有没有一种方法可以定期发送列表对象,然后创建一个新的对象进行拾取并继续操作?

Is there a way to periodically send the list object, and then create a new object to pickup and continue on?

推荐答案

从技术上讲,服务器只能对每个请求返回单个响应,因此无法执行所需的操作(缺少设置某种疯狂的套接字的方法)东西).

Technically the server can only return a single response to every request, so there is not way to do what you want (short of setting up some sort of crazy socket stuff).

我将翻转您正在做的事情,让您的javascript请求数据集中的数据块以1000个(或任意大小)的批处理为单位,并在请求下一个数据块时开始渲染.

I'd flip what you're doing on its head and have your javascript request chunks of the dataset in batches of 1000 (or whatever size), and have it start rendering while requesting the next chunk.

更好的是,您可以在UI中实现某种形式的无限滚动,以便仅在显示块之前及时请求下一个块,这样就不会向客户端发送不需要的数据.

Better yet, you could implement some form of infinite scrolling in your UI so that the next chunk is only requested just in time for it to be displayed, that way you're not sending unneeded data to the client.

这篇关于大型查询如何在C#/ASP.NET MVC 4部分中返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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