ASP.NET MVC中的jQuery网格绑定非常慢 [英] jQuery Grid Binding in ASP .NET MVC is so slow

查看:160
本文介绍了ASP.NET MVC中的jQuery网格绑定非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Infragistics jQuery网格在我的ASP.NET MVC应用程序。我的数据源是引用SQL数据库的ADO .NET实体模型。这是我的控制器的代码,用于设置网格,并提供数据源以从中拉取:

  public ActionResult Index )
{
var model = new GridModel();
model.DataSourceUrl = Url.Action(GetInstrumentListData);
this.InitializeGridOptions(model);
return View(model);
}

public JsonResult GetInstrumentListData()
{
var model = new GridModel();
this.InitializeGridOptions(model);
model.DataSource = _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable< InstrumentList>();
return model.GetData();
}

private void InitializeGridOptions(GridModel model)
{
创建列的代码...

model.DefaultColumnWidth =100px ;
model.Width =100%;
model.Height =700px;

model.Features.Add(new GridFiltering());

var sort = new GridSorting();
sort.Mode = SortingMode.Multiple;
model.Features.Add(sort);

var paging = new GridPaging();
paging.PageSize = 30;
model.Features.Add(paging);

var selection = new GridSelection();
selection.Mode = SelectionMode.Row;
selection.MultipleSelection = true;
model.Features.Add(selection);
}

网格正在花时间显示(25-40秒),所以我做了一些调查,它是 model.GetData()调用 GetInstrumentListData(),这一直在占用。根据Intellisense,这个函数首先执行数据绑定并生成JsonResult对象。



我以为可能是因为我试图显示总共1000条记录(即使分页被启用,只显示30个每个视图),也许这是一段时间将这些记录转换成JSON,所以我将记录的数量减少到10(从1.2mb的JSON数据到12.5kb)。没有时间差异。



这是Firebug的请求跟踪。



有关发生什么的任何想法?



编辑: @allentranks的答案和@AlastairPitts评论让我意识到,这实际上是我得到我的数据的来源。源不是一个表,而是一个视图,它是由我的DBA从一大堆疯狂的联接创建的。事实证明,运行查询需要13多秒,所以难怪它花费的时间要长一些。感谢您的帮助。

解决方案

我不知道为什么您的InstrumentLists需要在您的查询中被命令两次。

  _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable< InstrumentList>()。OrderBy(x =>标签); 

这应该工作:

  _db.InstrumentLists.OrderBy(x => x.Tag).ToList(); 

而且,您可能需要在标签列上创建一个索引,以更快速地执行查询。 / p>

I am using the Infragistics jQuery grid in my ASP .NET MVC application. My datasource is an ADO .NET Entity model referencing an SQL database. Here is the code from my controller to set up the grid and provide the datasource for it to pull from:

public ActionResult Index()
{
   var model = new GridModel();
   model.DataSourceUrl = Url.Action("GetInstrumentListData");
   this.InitializeGridOptions(model);
   return View(model);
}

public JsonResult GetInstrumentListData()
{
   var model = new GridModel();
   this.InitializeGridOptions(model);
   model.DataSource = _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>();
   return model.GetData();
}

private void InitializeGridOptions(GridModel model)
{
   Code to create columns...

   model.DefaultColumnWidth = "100px";
   model.Width = "100%";
   model.Height = "700px";

   model.Features.Add(new GridFiltering());

   var sort = new GridSorting();
   sort.Mode = SortingMode.Multiple;
   model.Features.Add(sort);

   var paging = new GridPaging();
   paging.PageSize = 30;
   model.Features.Add(paging);

   var selection = new GridSelection();
   selection.Mode = SelectionMode.Row;
   selection.MultipleSelection = true;
   model.Features.Add(selection);
}

The grid was taking ages to display (25-40 secs) so I did some investigating and it's the model.GetData() call in GetInstrumentListData() that is taking up all the time. According to Intellisense, this function first performs data binding and generates the JsonResult object.

I thought that maybe since I was attempting to display a total of 1000 records (even though pagination is enabled and only displaying 30 each view) that maybe it was taking a while to convert those records into JSON, so I reduced the amount of records to 10 (from 1.2mb of JSON data to 12.5kb). There was no difference in time.

Here is the request tracing from Firebug.

Any ideas on what is happening?

EDIT: @allentranks' answer and @AlastairPitts comment made me realise that it is in fact the source I am getting my data from. The source isn't a table but a view, which was created by my DBA from a whole bunch of crazy joins. Turns out that it takes 13+ secs to run the query, so its no wonder its taking so long to load. Thanks for your help.

解决方案

I am not sure why your InstrumentLists need to be ordered twice in your query.

_db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>().OrderBy(x => x.Tag);

this should work:

_db.InstrumentLists.OrderBy(x => x.Tag).ToList();

And, you maybe need to create an index on the Tag column to execute the query more quickly.

这篇关于ASP.NET MVC中的jQuery网格绑定非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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